Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from scipy.stats.stats import pearsonr | ||
|
||
if __name__ == '__main__': | ||
predictions = pd.read_csv('predictions.csv', index_col=0) | ||
true = pd.read_csv('true.csv', index_col=0) | ||
from vk_text_likeness.check import check | ||
|
||
for column in ['direct_likes_count', 'direct_reposts_count', 'non_direct_likes_count', 'non_direct_reposts_count']: | ||
index = [ind for ind in predictions.index if ind in true.index] | ||
x = predictions[column].loc[index] | ||
y_raw = true[column] | ||
y = [y_raw.loc[ind] for ind in index] | ||
x = x.values | ||
y = np.array(y) | ||
print(column, '\t', 'rmse', '\t', np.sqrt(np.mean((x - y) ** 2))) | ||
corr, pval = pearsonr(x, y) | ||
print(column, '\t', 'corr', '\t', corr) | ||
if __name__ == '__main__': | ||
predictions_df = pd.read_csv('predictions.csv', index_col=0) | ||
true_df = pd.read_csv('true.csv', index_col=0) | ||
check(predictions_df, true_df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
|
||
from sklearn.model_selection import KFold | ||
|
||
from vk_text_likeness.check import check | ||
from vk_text_likeness.predict_main import GroupPredict | ||
|
||
if __name__ == '__main__': | ||
group_id = int(os.sys.argv[1]) | ||
assert group_id > 0 | ||
access_token = os.sys.argv[2] | ||
|
||
group_predict = GroupPredict(group_id, access_token) | ||
group_predict.prepare() | ||
|
||
cv = KFold(5, shuffle=True) | ||
i = 0 | ||
for train_index, test_index in cv.split(group_predict.action_data.get_all()): | ||
print('\nCV: iter #{}'.format(i)) | ||
group_predict.fit(train_index) | ||
predictions_df = group_predict.predict(test_index) | ||
true_df = group_predict.get_true(predictions_df.index) | ||
check(predictions_df, true_df) | ||
i += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import numpy as np | ||
from scipy.stats.stats import pearsonr | ||
|
||
|
||
def check(predictions_df, true_df): | ||
index = [ind for ind in predictions_df.index if ind in true_df.index] | ||
for column in ['direct_likes_count', 'direct_reposts_count', 'non_direct_likes_count', 'non_direct_reposts_count']: | ||
x = predictions_df[column].loc[index] | ||
y_raw = true_df[column] | ||
y = [y_raw.loc[ind] for ind in index] | ||
x = x.values | ||
y = np.array(y) | ||
|
||
rmse = np.sqrt(np.mean((x - y) ** 2)) | ||
corr, pval = pearsonr(x, y) | ||
|
||
print(column) | ||
print('\t', 'rmse:', rmse) | ||
print('\t', 'corr:', corr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters