Skip to content

Commit

Permalink
[CHANGE] fix predict_window
Browse files Browse the repository at this point in the history
  • Loading branch information
marta_seq committed Feb 5, 2020
1 parent 4cc62e6 commit a0e1e31
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/propythia/machine_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def train_best_model(self,model,sample_weights=None, scaler=StandardScaler(),
if param_grid is None:
param_range = [0.00001, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0]
param_grid = [{'clf__C': param_range,
'clf__kernel': ['linear','rbf'],
'clf__kernel': ['linear'],
'clf__gamma': param_range
#'clf__kernel': ['rbf'] does not allow to retrieve feature importances with rbf kernel
}]
Expand Down Expand Up @@ -699,7 +699,9 @@ def predict_window(self,classifier, seq,x=None, window_size=20,gap=1,features=[]
features_to_select=self.X_data.columns
else:
features_to_select= features_names

x_predict_data=featuresDF[features_to_select]

# raw proability predictions of belonging or not
preds = classifier.predict_proba(x_predict_data)
#0 or 1 if belong or not
Expand All @@ -718,7 +720,6 @@ def predict_window(self,classifier, seq,x=None, window_size=20,gap=1,features=[]
pos_0=int
pos_1=int
rows = []
print(df_pred)

for index, row in df_pred.iterrows():
value=row['P_class1']
Expand Down Expand Up @@ -773,13 +774,13 @@ def predict_window(self,classifier, seq,x=None, window_size=20,gap=1,features=[]
df_new=df.drop(columns=['sequence', 'prevision'])
x=df_new.values.tolist() #not in pandas dataframe
remove_list=[]
print(df_new)
for row in range(len(x)-1):

pos_fin=x[row][0]
pos_ini=x[row][1]
prob=round(x[row][2],3)
scale_prob=x[row][3]
for row in range(len(x)-1):
pos_fin=x[row][3]
pos_ini=x[row][2]
prob=round(x[row][0],3)
x[row][0] = round(x[row][0], 4)
scale_prob=x[row][1]
key=x[row][4]

if x[row][4]==x[row+1][4]:
Expand All @@ -795,10 +796,11 @@ def predict_window(self,classifier, seq,x=None, window_size=20,gap=1,features=[]

# add sequence
for row in range(len(x)):
seqs=seq[int(x[row][1]):int(x[row][0])]
seqs=seq[int(x[row][2]):int(x[row][3])]
x[row].append(seqs)

final_df=pd.DataFrame(x, columns=['pos_-1', 'pos_0','probability','scale_probability','key','sequence'])
final_df=pd.DataFrame(x, columns=['probability','scale_probability','pos_0','pos_-1','key','sequence'])
final_df=final_df.drop(columns=['key'])
final_df = final_df[['pos_0','pos_-1','probability','scale_probability','sequence']]
return final_df

0 comments on commit a0e1e31

Please sign in to comment.