Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import pandas as pd
  4. import pickle
  5.  
  6. dataset = pd.read_csv('sales.csv')
  7.  
  8. dataset['rate'].fillna(0, inplace=True)
  9.  
  10. dataset['sales_in_first_month'].fillna(dataset['sales_in_first_month'].mean(), inplace=True)
  11.  
  12. X = dataset.iloc[:, :3]
  13.  
  14. def convert_to_int(word):
  15. word_dict = {'one':1, 'two':2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8,
  16. 'nine':9, 'ten':10, 'eleven':11, 'twelve':12, 'zero':0, 0: 0}
  17. return word_dict[word]
  18.  
  19. X['rate'] = X['rate'].apply(lambda x : convert_to_int(x))
  20.  
  21. y = dataset.iloc[:, -1]
  22.  
  23. from sklearn.linear_model import LinearRegression
  24. regressor = LinearRegression()
  25.  
  26. regressor.fit(X, y)
  27.  
  28. pickle.dump(regressor, open('model.pkl','wb'))
  29.  
  30. model = pickle.load(open('model.pkl','rb'))
  31. print(model.predict([[4, 300, 500]]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement