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
test = df[17500:] | |
X_test = test[['speed', 'thickness', 'delta']] | |
y_test = test[['I']] | |
X_test_minmax = mm_scaler.transform(X_test[['thickness', 'delta']]) | |
kn = neigh.kneighbors(X_test_minmax, return_distance=False) | |
test = test.assign(ml_speed=[X_train_clean.loc[i, 'speed'].quantile(0.8) for i in kn]) | |
test = test.assign(I_new_predict=bst.predict(test[['ml_speed', 'thickness', 'delta']])) | |
test.loc[:, 'ml_speed'] = test['ml_speed'] + (limit - 600 * 3 - test['I_new_predict']) / step | |
test.loc[:, 'I_new'] = test['I'] + (test['ml_speed'] - test['speed']) * 2000 | |
print((test.I_new > limit).sum() / test.shape[0]) |
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
dev.loc[:, 'ml_speed'] = dev['ml_speed'] + (limit - 600 * 3 - dev['I_new_predict']) / step | |
dev.loc[:, 'I_new'] = dev['I'] + (dev['ml_speed'] - dev['speed']) * 2000 | |
print((dev.I_new > limit).sum() / dev.shape[0]) | |
print(dev.ml_speed.mean() / dev.speed.mean()) |
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
coefs = {} | |
for i in range(6, 19): | |
train_new = train.copy() | |
train_new['bin'] = ((resc.predict(Xc) < (i + 2)) & (resc.predict(Xc) >= i)).astype(int) | |
Xcb = train_new[train_new.bin == 1][['speed', 'thickness', 'delta']] | |
Xcb = sm.add_constant(Xcb) | |
Ycb = train_new[train_new.bin == 1][['I']] | |
modcb = sm.OLS(Ycb, Xcb) | |
rescb = modcb.fit() | |
coefs[i] = rescb.params['speed'] |
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
Xc = train[['thickness', 'delta']] | |
Xc = sm.add_constant(Xc) | |
Yc = train[['speed']] | |
modc = sm.OLS(Yc, Xc) | |
resc = modc.fit() |
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
X_dev_minmax = mm_scaler.transform(X_dev[['thickness', 'delta']]) | |
kn = neigh.kneighbors(X_dev_minmax, return_distance=False) | |
dev = dev.assign(ml_speed=[X_train_clean.loc[i, 'speed'].quantile(0.8) for i in kn]) | |
print(dev.ml_speed.mean() / dev.speed.mean()) | |
dev = dev.assign(I_new=dev['I'] + (dev['ml_speed'] - dev['speed']) * 2000) | |
dev = dev.assign(I_new_predict=bst.predict(dev[['ml_speed', 'thickness', 'delta']])) | |
print((dev.loc[:, 'I_new'] > limit).sum() / dev.shape[0]) |
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
mm_scaler = preprocessing.MinMaxScaler() | |
X_train_minmax = mm_scaler.fit_transform(X_train[['thickness', 'delta']]) | |
neigh = KNeighborsRegressor(n_neighbors=20) | |
X_train_clean = X_train[y_train['I'] < limit].reset_index(drop=True) | |
X_train_clean_minmax = mm_scaler.transform(X_train_clean[['thickness', 'delta']]) | |
neigh.fit(X_train_clean_minmax, X_train_clean[['speed']]) |
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
test = test.assign(I_new=test['I'] + (test['ml_speed'] - test['speed']) * 2000) | |
print((test.I_new > limit).sum() / test.shape[0]) |
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
def speed_choose(thickness, delta, model=bst, prelimit=limit - 600 * 3): | |
speeds = list(range(4, 22)) | |
speeds.reverse() | |
for speed in speeds: | |
df = pd.DataFrame({'speed': [speed], 'thickness': [thickness], 'delta': [delta]}) | |
if model.predict(df) < prelimit: | |
return speed | |
return 4 |
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
df['I'] = 3000 + 1500 * (df['thickness'] ** 0.8 + 5 * df['delta'] ** 1.4) + 2000 * df['speed'] |
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
df['speed'] = 25 - 0.1 * df['thickness'] ** 0.9 - 4 * df['delta'] ** 1.1 |