def main(): from sklearn.ensemble import RandomForestRegressor # Load and convert data X_train, X_test, y_train, y_test = bench.load_data(params) # Create our random forest regressor regr = RandomForestRegressor(criterion=params.criterion, n_estimators=params.num_trees, max_depth=params.max_depth, max_features=params.max_features, min_samples_split=params.min_samples_split, max_leaf_nodes=params.max_leaf_nodes, min_impurity_decrease=params.min_impurity_decrease, bootstrap=params.bootstrap, random_state=params.seed, n_jobs=params.n_jobs) fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) y_pred = regr.predict(X_train) train_rmse = bench.rmse_score(y_pred, y_train) predict_time, y_pred = bench.measure_function_time( regr.predict, X_test, params=params) test_rmse = bench.rmse_score(y_pred, y_test) bench.print_output(library='sklearn', algorithm='decision_forest_regression', stages=['training', 'prediction'], params=params, functions=['df_regr.fit', 'df_regr.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse], data=[X_train, X_test], alg_instance=regr)
def main(): from sklearn.linear_model import ElasticNet # Load data X_train, X_test, y_train, y_test = bench.load_data(params) # Create our regression object regr = ElasticNet(fit_intercept=params.fit_intercept, l1_ratio=params.l1_ratio, alpha=params.alpha, tol=params.tol, max_iter=params.maxiter, copy_X=False) # Time fit fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) # Time predict predict_time, pred_train = bench.measure_function_time(regr.predict, X_train, params=params) train_rmse = bench.rmse_score(pred_train, y_train) pred_test = regr.predict(X_test) test_rmse = bench.rmse_score(pred_test, y_test) bench.print_output(library='sklearn', algorithm='elastic-net', stages=['training', 'prediction'], params=params, functions=['ElasticNet.fit', 'ElasticNet.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse], data=[X_train, X_train], alg_instance=regr)
def main(): from sklearn.neighbors import KNeighborsRegressor # Load generated data X_train, X_test, y_train, y_test = bench.load_data(params) params.n_classes = len(np.unique(y_train)) # Create a regression object knn_regr = KNeighborsRegressor(n_neighbors=params.n_neighbors, weights=params.weights, algorithm=params.method, metric=params.metric, n_jobs=params.n_jobs) # Measure time and accuracy on fitting train_time, _ = bench.measure_function_time( knn_regr.fit, X_train, y_train, params=params) if params.task == 'regression': y_pred = knn_regr.predict(X_train) train_rmse = bench.rmse_score(y_train, y_pred) train_r2 = bench.r2_score(y_train, y_pred) # Measure time and accuracy on prediction if params.task == 'regression': predict_time, yp = bench.measure_function_time(knn_regr.predict, X_test, params=params) test_rmse = bench.rmse_score(y_test, yp) test_r2 = bench.r2_score(y_test, yp) else: predict_time, _ = bench.measure_function_time(knn_regr.kneighbors, X_test, params=params) if params.task == 'regression': bench.print_output( library='sklearn', algorithm=knn_regr._fit_method + '_knn_regr', stages=['training', 'prediction'], params=params, functions=['knn_regr.fit', 'knn_regr.predict'], times=[train_time, predict_time], metric_type=['rmse', 'r2_score'], metrics=[[train_rmse, test_rmse], [train_r2, test_r2]], data=[X_train, X_test], alg_instance=knn_regr, ) else: bench.print_output( library='sklearn', algorithm=knn_regr._fit_method + '_knn_search', stages=['training', 'search'], params=params, functions=['knn_regr.fit', 'knn_regr.kneighbors'], times=[train_time, predict_time], metric_type=None, metrics=[], data=[X_train, X_test], alg_instance=knn_regr, )
def main(): from sklearn.svm import NuSVR X_train, X_test, y_train, y_test = bench.load_data(params) y_train = np.asfortranarray(y_train).ravel() if params.gamma is None: params.gamma = 1.0 / X_train.shape[1] cache_size_bytes = bench.get_optimal_cache_size( X_train.shape[0], max_cache=params.max_cache_size) params.cache_size_mb = cache_size_bytes / 1024**2 params.n_classes = len(np.unique(y_train)) regr = NuSVR(C=params.C, nu=params.nu, kernel=params.kernel, cache_size=params.cache_size_mb, tol=params.tol, gamma=params.gamma, degree=params.degree) fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) params.sv_len = regr.support_.shape[0] predict_train_time, y_pred = bench.measure_function_time(regr.predict, X_train, params=params) train_rmse = bench.rmse_score(y_train, y_pred) train_r2 = bench.r2_score(y_train, y_pred) _, y_pred = bench.measure_function_time(regr.predict, X_test, params=params) test_rmse = bench.rmse_score(y_test, y_pred) test_r2 = bench.r2_score(y_test, y_pred) bench.print_output( library='sklearn', algorithm='nuSVR', stages=['training', 'prediction'], params=params, functions=['NuSVR.fit', 'NuSVR.predict'], times=[fit_time, predict_train_time], metric_type=['rmse', 'r2_score', 'n_sv'], metrics=[ [train_rmse, test_rmse], [train_r2, test_r2], [int(regr.n_support_.sum()), int(regr.n_support_.sum())], ], data=[X_train, X_train], alg_instance=regr, )
def main(): from sklearn.linear_model import Lasso # Load data X_train, X_test, y_train, y_test = bench.load_data(params) # Create our regression object regr = Lasso(fit_intercept=params.fit_intercept, alpha=params.alpha, tol=params.tol, max_iter=params.maxiter, copy_X=False) # Time fit fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) # Time predict predict_time, yp = bench.measure_function_time(regr.predict, X_train, params=params) train_rmse = bench.rmse_score(y_train, yp) train_r2 = bench.r2_score(y_train, yp) yp = regr.predict(X_test) test_rmse = bench.rmse_score(y_test, yp) test_r2 = bench.r2_score(y_test, yp) bench.print_output( library='sklearn', algorithm='lasso', stages=['training', 'prediction'], params=params, functions=['Lasso.fit', 'Lasso.predict'], times=[fit_time, predict_time], metric_type=['rmse', 'r2_score', 'iter'], metrics=[ [train_rmse, test_rmse], [train_r2, test_r2], [int(regr.n_iter_), int(regr.n_iter_)], ], data=[X_train, X_test], alg_instance=regr, )
def main(): from sklearn.linear_model import LinearRegression # Load data X_train, X_test, y_train, y_test = bench.load_data( params, generated_data=['X_train', 'y_train']) # Create our regression object regr = LinearRegression(fit_intercept=params.fit_intercept, n_jobs=params.n_jobs, copy_X=False) # Time fit fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) # Time predict predict_time, yp = bench.measure_function_time(regr.predict, X_test, params=params) test_rmse = bench.rmse_score(y_test, yp) test_r2 = bench.r2_score(y_test, yp) yp = regr.predict(X_train) train_rmse = bench.rmse_score(y_train, yp) train_r2 = bench.r2_score(y_train, yp) bench.print_output( library='sklearn', algorithm='lin_reg', stages=['training', 'prediction'], params=params, functions=['Linear.fit', 'Linear.predict'], times=[fit_time, predict_time], metric_type=['rmse', 'r2_score'], metrics=[[train_rmse, test_rmse], [train_r2, test_r2]], data=[X_train, X_test], alg_instance=regr, )
def main(): from sklearn.linear_model import ElasticNet # Load data X_train, X_test, y_train, y_test = bench.load_data(params) # Create our regression object regr = ElasticNet(fit_intercept=params.fit_intercept, l1_ratio=params.l1_ratio, alpha=params.alpha, tol=params.tol, max_iter=params.maxiter) # Time fit fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) # Time predict predict_time, y_pred = bench.measure_function_time(regr.predict, X_train, params=params) train_rmse = bench.rmse_score(y_train, y_pred) train_r2 = bench.r2_score(y_train, y_pred) y_pred = regr.predict(X_test) test_rmse = bench.rmse_score(y_test, y_pred) test_r2 = bench.r2_score(y_test, y_pred) bench.print_output( library='sklearn', algorithm='elasticnet', stages=['training', 'prediction'], params=params, functions=['ElasticNet.fit', 'ElasticNet.predict'], times=[fit_time, predict_time], metric_type=['rmse', 'r2_score', 'iter'], metrics=[ [train_rmse, test_rmse], [train_r2, test_r2], [int(regr.n_iter_), int(regr.n_iter_)], ], data=[X_train, X_train], alg_instance=regr, )
def main(): from sklearn.linear_model import Ridge # Load data X_train, X_test, y_train, y_test = bench.load_data( params, generated_data=['X_train', 'y_train']) # Create our regression object regr = Ridge(fit_intercept=params.fit_intercept, alpha=params.alpha, solver=params.solver) # Time fit fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) # Time predict predict_time, yp = bench.measure_function_time(regr.predict, X_test, params=params) test_rmse = bench.rmse_score(yp, y_test) yp = regr.predict(X_train) train_rmse = bench.rmse_score(yp, y_train) bench.print_output(library='sklearn', algorithm='ridge_regression', stages=['training', 'prediction'], params=params, functions=['Ridge.fit', 'Ridge.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse], data=[X_train, X_test], alg_instance=regr)
tol=params.tol, max_iter=params.maxiter, copy_X=False) columns = ('batch', 'arch', 'prefix', 'function', 'threads', 'dtype', 'size', 'time') # Time fit fit_time, _ = measure_function_time(regr.fit, X_train, y_train, params=params) # Time predict predict_time, pred_train = measure_function_time(regr.predict, X_train, params=params) train_rmse = rmse_score(pred_train, y_train) pred_test = regr.predict(X_test) test_rmse = rmse_score(pred_test, y_test) print_output(library='sklearn', algorithm='lasso', stages=['training', 'prediction'], columns=columns, params=params, functions=['Lasso.fit', 'Lasso.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse], data=[X_train, X_test], alg_instance=regr)
def test_predict(Xp, model): regr_predict = ridge_regression_prediction(fptype=getFPType(Xp)) return regr_predict.compute(Xp, model) # Time fit fit_time, res = bench.measure_function_time(test_fit, X_train, y_train, params=params) # Time predict predict_time, yp = bench.measure_function_time(test_predict, X_test, res.model, params=params) test_rmse = bench.rmse_score(yp.prediction, y_test) pres = test_predict(X_train, res.model) train_rmse = bench.rmse_score(pres.prediction, y_train) bench.print_output(library='daal4py', algorithm='ridge_regression', stages=['training', 'prediction'], params=params, functions=['Ridge.fit', 'Ridge.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse], data=[X_train, X_test])
def fit(regr, X, y): return regr.fit(X, y) def predict(regr, X): return regr.predict(X, predict_model='GPU') fit_time, _ = bench.measure_function_time(fit, regr, X_train, y_train, params=params) y_pred = predict(regr, X_train) train_rmse = bench.rmse_score(y_pred, y_train) predict_time, y_pred = bench.measure_function_time(predict, regr, X_test, params=params) test_rmse = bench.rmse_score(y_pred, y_test) bench.print_output(library='cuml', algorithm='df_regr', stages=['training', 'prediction'], params=params, functions=['df_regr.fit', 'df_regr.predict'], times=[fit_time, predict_time], metric_type='rmse', metrics=[train_rmse, test_rmse],
# Create our regression object regr = Lasso(fit_intercept=params.fit_intercept, alpha=params.alpha, tol=params.tol, max_iter=params.maxiter) # Time fit fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) # Time predict predict_time, pred_train = bench.measure_function_time(regr.predict, X_train, params=params) train_rmse = bench.rmse_score(pred_train, y_train) pred_test = regr.predict(X_test) test_rmse = bench.rmse_score(pred_test, y_test) bench.print_output(library='sklearn', algorithm='lasso', stages=['training', 'prediction'], params=params, functions=['Lasso.fit', 'Lasso.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse], data=[X_train, X_test], alg_instance=regr)
# Create our regression object regr = Ridge(fit_intercept=params.fit_intercept, alpha=params.alpha, solver=params.solver) # Time fit fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) # Time predict predict_time, yp = bench.measure_function_time(regr.predict, X_test, params=params) test_rmse = bench.rmse_score(yp, y_test) yp = regr.predict(X_train) train_rmse = bench.rmse_score(yp, y_train) bench.print_output(library='sklearn', algorithm='ridge_regression', stages=['training', 'prediction'], params=params, functions=['Ridge.fit', 'Ridge.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse], data=[X_train, X_test], alg_instance=regr)
# Time fit and predict fit_time, res = measure_function_time( df_regr_fit, X_train, y_train, n_trees=params.num_trees, n_features_per_node=params.max_features, max_depth=params.max_depth, min_impurity=params.min_impurity_decrease, bootstrap=params.bootstrap, seed=params.seed, params=params) yp = df_regr_predict(X_train, res) train_rmse = rmse_score(yp, y_train) predict_time, yp = measure_function_time(df_regr_predict, X_test, res, params=params) test_rmse = rmse_score(yp, y_test) print_output(library='daal4py', algorithm='decision_forest_regression', stages=['training', 'prediction'], columns=columns, params=params, functions=['df_regr.fit', 'df_regr.predict'], times=[fit_time, predict_time],
columns = ('batch', 'arch', 'prefix', 'function', 'threads', 'dtype', 'size', 'method', 'time') # Time fit fit_time, res = measure_function_time(test_fit, X_train, y_train, params=params) # Time predict predict_time, pres = measure_function_time(test_predict, X_test, res.model, params=params) test_rmse = rmse_score(pres.prediction, y_test) pres = test_predict(X_train, res.model) train_rmse = rmse_score(pres.prediction, y_train) print_output(library='daal4py', algorithm='linear_regression', stages=['training', 'prediction'], columns=columns, params=params, functions=['Linear.fit', 'Linear.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse], data=[X_train, X_test])
X_train, X_test, y_train, y_test = bench.load_data(params) if params.gamma is None: params.gamma = 1.0 / X_train.shape[1] cache_size_bytes = bench.get_optimal_cache_size(X_train.shape[0], max_cache=params.max_cache_size) params.cache_size_mb = cache_size_bytes / 1024**2 params.n_classes = y_train[y_train.columns[0]].nunique() regr = SVR(C=params.C, epsilon=params.epsilon, kernel=params.kernel, cache_size=params.cache_size_mb, tol=params.tol, gamma=params.gamma, degree=params.degree) fit_time, _ = bench.measure_function_time(regr.fit, X_train, y_train, params=params) predict_train_time, y_pred = bench.measure_function_time( regr.predict, X_train, params=params) train_rmse = bench.rmse_score(y_train, y_pred) predict_test_time, y_pred = bench.measure_function_time( regr.predict, X_test, params=params) test_rmse = bench.rmse_score(y_test, y_pred) bench.print_output(library='cuml', algorithm='svr', stages=['training', 'prediction'], params=params, functions=['SVR.fit', 'SVR.predict'], times=[fit_time, predict_train_time], metric_type='rmse', metrics=[train_rmse, test_rmse], data=[X_train, X_train], alg_instance=regr)
n_estimators=params.num_trees, max_depth=params.max_depth, max_features=params.max_features, min_samples_split=params.min_samples_split, max_leaf_nodes=params.max_leaf_nodes, min_impurity_decrease=params.min_impurity_decrease, bootstrap=params.bootstrap, random_state=params.seed) columns = ('batch', 'arch', 'prefix', 'function', 'threads', 'dtype', 'size', 'num_trees', 'time') fit_time, _ = measure_function_time(regr.fit, X_train, y_train, params=params) y_pred = regr.predict(X_train) train_rmse = rmse_score(y_pred, y_train) predict_time, y_pred = measure_function_time(regr.predict, X_test, params=params) test_rmse = rmse_score(y_pred, y_test) print_output(library='sklearn', algorithm='decision_forest_regression', stages=['training', 'prediction'], columns=columns, params=params, functions=['df_regr.fit', 'df_regr.predict'], times=[fit_time, predict_time], accuracy_type='rmse', accuracies=[train_rmse, test_rmse],