def regression(self): self.nn = self.get_pure_model() self.nn.fit(self.data.Xtrain, self.data.Ytrain.to_numpy().flatten()) nn_Ypred = self.nn.predict(self.data.Xtest) self.nn_mean_squared_error = mean_squared_error(self.data.Ytest, nn_Ypred) self.nn_r2_score = r2_score(self.data.Ytest, nn_Ypred) print_training_result_summary('NeuralNetwork', self.nn_mean_squared_error, self.nn_r2_score)
def regression(self): self.lasso = linear_model.Lasso(alpha=0.1) self.lasso.fit(self.data.Xtrain, self.data.Ytrain) lasso_Ypred = self.lasso.predict(self.data.Xtest) self.lasso_mean_squared_error = mean_squared_error( self.data.Ytest, lasso_Ypred) self.lasso_r2_score = r2_score(self.data.Ytest, lasso_Ypred) print_training_result_summary('Lasso', self.lasso_mean_squared_error, self.lasso_r2_score)
def regression(self): self.eNet = ElasticNetModel(alpha=1.0) self.eNet.fit(self.data.Xtrain, self.data.Ytrain) eNet_Ypred = self.eNet.predict(self.data.Xtest) self.eNet_mean_squared_error = mean_squared_error( self.data.Ytest, eNet_Ypred) self.eNet_r2_score = r2_score(self.data.Ytest, eNet_Ypred) print_training_result_summary('Elastic Net', self.eNet_mean_squared_error, self.eNet_r2_score)
def regression(self): self.DecisionTreeM = tree.DecisionTreeRegressor() self.DecisionTreeM.fit(self.data.Xtrain, self.data.Ytrain) DecisionTree_Ypred = self.DecisionTreeM.predict(self.data.Xtest) self.DecisionTree_mean_squared_error = mean_squared_error( self.data.Ytest, DecisionTree_Ypred) self.DecisionTree_r2_score = r2_score(self.data.Ytest, DecisionTree_Ypred) print_training_result_summary('Decision Tree', self.DecisionTree_mean_squared_error, self.DecisionTree_r2_score)
def regression(self): self.lasso = linear_model.Lasso(alpha=1.0) self.lasso.fit(self.data.Xtrain, self.data.Ytrain) lasso_Ypred = self.lasso.predict(self.data.Xtest) self.lasso_mean_squared_error = mean_squared_error( self.data.Ytest, lasso_Ypred) self.lasso_r2_score = r2_score(self.data.Ytest, lasso_Ypred) print_training_result_summary('Lasso', self.lasso_mean_squared_error, self.lasso_r2_score) self.save_the_trained_model() self.save_the_class_included_the_trained_model() return training_result_summary('Lasso', self.lasso_mean_squared_error, self.lasso_r2_score)
def regression(self): self.ridge = RidgeModel(alpha=1.0) self.ridge.fit(self.data.Xtrain, self.data.Ytrain) ridge_Ypred = self.ridge.predict(self.data.Xtest) self.ridge_mean_squared_error = mean_squared_error( self.data.Ytest, ridge_Ypred) self.ridge_r2_score = r2_score(self.data.Ytest, ridge_Ypred) print_training_result_summary('Ridge', self.ridge_mean_squared_error, self.ridge_r2_score) self.save_the_trained_model() self.save_the_class_included_the_trained_model() return training_result_summary('Ridge', self.ridge_mean_squared_error, self.ridge_r2_score)
def regression(self): """ Traing the machine learning model on the internal data. """ self.model = linear_model.LinearRegression() self.model.fit(self.data.Xtrain, self.data.Ytrain) model_Ypred = self.model.predict(self.data.Xtest) self.model_mean_squared_error = mean_squared_error(self.data.Ytest, model_Ypred) self.model_r2_score = r2_score(self.data.Ytest, model_Ypred) print_training_result_summary( 'LinearRegression', self.model_mean_squared_error, self.model_r2_score) self.save_the_trained_model() self.save_the_class_included_the_trained_model() return training_result_summary( 'LinearRegression', self.model_mean_squared_error, self.model_r2_score)
def regression(self): warnings.filterwarnings("ignore") self.RandomForestM = RandomForestRegressor(max_depth=2, random_state=0) self.RandomForestM.fit(self.data.Xtrain, self.data.Ytrain) RandomForest_Ypred = self.RandomForestM.predict(self.data.Xtest) self.RandomForest_mean_squared_error = mean_squared_error( self.data.Ytest, RandomForest_Ypred) self.RandomForest_r2_score = r2_score(self.data.Ytest, RandomForest_Ypred) print_training_result_summary('Random Forest', self.RandomForest_mean_squared_error, self.RandomForest_r2_score) self.save_the_trained_model() self.save_the_class_included_the_trained_model() return training_result_summary('Random Forest', self.RandomForest_mean_squared_error, self.RandomForest_r2_score)
def regression(self): self.nn = self.get_pure_model() self.data.Y = self.data.Y.to_numpy() self.data.X = self.data.X.to_numpy() # shape the data ex. (5000,) self.data.Y = self.data.Y[:, 0] # Partition the data into training and test sets. self.data.Xtrain, self.data.Xtest, self.data.Ytrain, self.data.Ytest = train_test_split(self.data.X, self.data.Y, test_size=0.33, random_state=42) self.nn.fit(self.data.Xtrain, self.data.Ytrain) nn_Ypred = self.nn.predict(self.data.Xtest) self.nn_mean_squared_error = mean_squared_error(self.data.Ytest, nn_Ypred) self.nn_r2_score = r2_score(self.data.Ytest, nn_Ypred) print_training_result_summary('NeuralNetwork', self.nn_mean_squared_error, self.nn_r2_score) self.save_the_trained_model() self.save_the_class_included_the_trained_model() return training_result_summary('NeuralNetwork', self.nn_mean_squared_error, self.nn_r2_score)