SHARE
TWEET

Untitled

a guest Oct 21st, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Assigning Linear Regression to variable
  2. model_sklearn = LinearRegression()
  3.  
  4.  
  5. # Create a test set and training set
  6. X_train, X_test, y_train, y_test = train_test_split(features_DSH.to_numpy().reshape(-1,1),
  7.                                                     Target_DSH.to_numpy(), test_size= 0.10,
  8.                                                     random_state= 30)
  9.  
  10. # Fitting the model to the training set
  11. model_sklearn.fit(X_train, y_train)
  12.  
  13. # Predictions
  14. y_pred = model_sklearn.predict(X_test)
  15. printString = 'Residual as the Difference between Test Scores & Predicted Scores:'
  16. printString_ = 'Residual using (r = y - X*beta ):'
  17. printStr = 'Parameters (Slope/Intercept):'
  18. parameters = np.array([model_sklearn.coef_[0], model_sklearn.intercept_])
  19. # Output Dataframes
  20. printPTS = pd.DataFrame.from_dict({'Predicted Test Scores': y_pred})
  21. printParameters = pd.DataFrame.from_dict({printStr: parameters})
  22. printR1 = pd.DataFrame.from_dict({printString: (y_test - y_pred)})
  23. printR2 = pd.DataFrame.from_dict({printString_: finding_residuals(X_test, y_test, model_sklearn.intercept_, model_sklearn.coef_[0]).flatten()})
  24. printRMSE = pd.DataFrame.from_dict({'RMSE:': [np.sqrt(metrics.mean_squared_error(y_test, y_pred))]})
  25.  
  26. # Outputting to file
  27. count = 1
  28. outputDataframeList = [printPTS, printParameters, printR1, printR2, printRMSE]
  29. for outputDataframe in outputDataframeList:
  30.     filepath = '/Users/Chris/Documents/Programming_Practice/gistHub/slrDFTTS_' + str(count) + '.csv'
  31.     with open(filepath, 'w') as f:
  32.         outputDataframe.to_csv(path_or_buf= f)
  33.     count += 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top