Guest User

Untitled

a guest
Jan 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. # Load the Diabetes Housing dataset
  2. columns = “age sex bmi map tc ldl hdl tch ltg glu”.split() # Declare the columns names
  3. diabetes = datasets.load_diabetes() # Call the diabetes dataset from sklearn
  4. df = pd.DataFrame(diabetes.data, columns=columns) # load the dataset as a pandas data frame
  5. y = diabetes.target # define the target variable (dependent variable) as y
  6. X_train, X_test, y_train, y_test = train_test_split(df, y, test_size=0.2)
  7. # fit a model
  8. lm = linear_model.LinearRegression()
  9. model = lm.fit(X_train, y_train)
  10. predictions = lm.predict(X_test)
  11. accuracy_score(y_test, predictions)
  12.  
  13. from sklearn.model_selection import cross_val_score
  14. accuracies = cross_val_score(estimator = model, X = X_train, y = y_train, cv = 7, n_jobs = 1)
  15. print accuracy_score(y_test, predictions)
  16.  
  17. cr=0
  18. for i in range(0,7):
  19. X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2)
  20. lm = linear_model.LinearRegression()
  21. model = lm.fit(X_train, y_train)
  22. predictions = lm.predict(X_test)
  23. #from sklearn.metrics import accuracy_score
  24. print accuracy_score(y_test, predictions)
  25. cr=cr+accuracy_score(y_test, predictions)
  26. result=cr/10
Add Comment
Please, Sign In to add comment