Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. import datetime
  5. import seaborn as sns
  6. #PLOTLY
  7. import plotly
  8. import plotly.plotly as py
  9. import plotly.offline as offline
  10. import plotly.graph_objs as go
  11. from plotly.offline import download_plotlyjs, init_notebook_mode,plot,iplot
  12. import cufflinks as cf
  13. cf.set_config_file(offline=True)
  14. from plotly.graph_objs import Scatter, Figure, Layout
  15.  
  16. data = pd.read_csv('/Users/rustamislamnurov/Desktop/train.csv', nrows=1101)
  17. print(data.head())
  18. print(data.isnull().sum())
  19. #data = data.dropna()
  20. #sns.distplot(data['fare'])
  21. #plt.title('asdda')
  22. from sklearn.model_selection import train_test_split
  23. from sklearn import metrics
  24. from sklearn.metrics import mean_squared_error
  25. from sklearn.model_selection import train_test_split, cross_val_score
  26. from sklearn.linear_model import LinearRegression
  27. import xgboost as xgb
  28. from sklearn.ensemble import RandomForestRegressor
  29. ml = data[1000:]
  30. y = ml['fare']
  31. X = ml.drop(['fare','date','time'],axis = 1)
  32. X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=43, test_size = 0.3)
  33. randomForest = RandomForestRegressor(random_state=42)
  34. randomForest.fit(X_train, y_train)
  35. randomForestPredict = randomForest.predict(X_test)
  36. randomForest_mse = mean_squared_error(y_test, randomForestPredict)
  37. randomForestMSE = np.sqrt(randomForest_mse)
  38. print(randomForestMSE)
  39. model = RandomForestRegressor(n_estimators=25, max_features=5, max_depth=25, min_samples_split=3,
  40. min_samples_leaf=2, random_state=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement