Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Load the Diabetes Housing dataset
- columns = “age sex bmi map tc ldl hdl tch ltg glu”.split() # Declare the columns names
- diabetes = datasets.load_diabetes() # Call the diabetes dataset from sklearn
- df = pd.DataFrame(diabetes.data, columns=columns) # load the dataset as a pandas data frame
- y = diabetes.target # define the target variable (dependent variable) as y
- X_train, X_test, y_train, y_test = train_test_split(df, y, test_size=0.2)
- # fit a model
- lm = linear_model.LinearRegression()
- model = lm.fit(X_train, y_train)
- predictions = lm.predict(X_test)
- accuracy_score(y_test, predictions)
- from sklearn.model_selection import cross_val_score
- accuracies = cross_val_score(estimator = model, X = X_train, y = y_train, cv = 7, n_jobs = 1)
- print accuracy_score(y_test, predictions)
- cr=0
- for i in range(0,7):
- X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2)
- lm = linear_model.LinearRegression()
- model = lm.fit(X_train, y_train)
- predictions = lm.predict(X_test)
- #from sklearn.metrics import accuracy_score
- print accuracy_score(y_test, predictions)
- cr=cr+accuracy_score(y_test, predictions)
- result=cr/10
Add Comment
Please, Sign In to add comment