<jupyter_start><jupyter_text>Diabetes<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from sklearn import datasets
diabetes = datasets.load_diabetes()
diabetes
data = np.c_[diabetes.data, diabetes.target]
columns = np.append(diabetes.feature_names, ["target"])
dataset = pd.DataFrame(data, columns=columns)
dataset.head()
print("--------Exploring Diabetes Data --------")
print("Diabetes Data")
print('-'*60)
print("Dataset information") 
print(dataset.info(memory_usage='deep',verbose=False))
print('-'*60)
print(dataset.info())
print('-'*60)
print("Data type:")
print(dataset.dtypes)
print('-'*60)
print("Check unique values wihtout NaN")
print(dataset.nunique())
print('-'*60)
print("Data shape:")
print(dataset.shape)
print('-'*60)
print("Data columns Names:")
print(dataset.columns)
print('-'*60)
print("Check for NaNs:")
print(dataset.isnull().values.any())
print('-'*60)
print("Data Statistics Summary:")
print(dataset.describe())
# if have a NaN
print('-'*60)
print(dataset.isnull().sum())
dataset.corr(method='pearson')
dataset.corr(method='kendall')
dataset.hist(sharex=False, sharey=False, xlabelsize=1, ylabelsize=1, figsize=(12,6))
plt.show()
dataset.plot(kind='density', subplots=True, layout=(4,4), sharex=False, legend=False, fontsize=1, figsize=(12,6))
plt.show()
dataset.plot(kind='box', subplots=True, layout=(4,4), sharex=False, sharey=False, fontsize=8, figsize=(12,10))
plt.show()
from pandas.tools.plotting import scatter_matrix

scatter_matrix(dataset, figsize=(12,12))
plt.show()
# Seperate train and test data
from sklearn.model_selection import train_test_split

X = dataset.loc[:,dataset.columns!='target']
Y = dataset['target']
# Random State makes input fixed value
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=0)
from sklearn.linear_model import LinearRegression
# 1. Set up the model
model = LinearRegression()
# 2. Use fit
model.fit(X_train, y_train)
# 3. Check the score
model.score(X_test, y_test)
# A positive sign indicates that as the predictor variable increases, the response variable also increases. 
# A negative sign indicates that as the predictor variable increases, the response variable decreases.
print('Coefficients:', model.coef_) # Get the coefficients, beta
print('intercept:', model.intercept_) # Get the intercept
print('Predict:', model.predict(X_test)) # Predict data
# plot prediction and actual data
y_pred = model.predict(X_test) 
plt.plot(y_test, y_pred, '.')

# plot a line, a perfit predict would all fall on this line
x = np.linspace(0, 330, 100)
y = x
plt.plot(x, y)
plt.show()<jupyter_output><empty_output><jupyter_text>Improve the model<jupyter_code># Change random state to 42
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=42)
# 1. Set up the model
model = LinearRegression()
# 2. Use fit
model.fit(X_train, y_train)
# 3. Check the score
model.score(X_test, y_test)
# Increase the test size to 30 percent
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=42)
# 1. Set up the model
model = LinearRegression()
# 2. Use fit
model.fit(X_train, y_train)
# 3. Check the score
model.score(X_test, y_test)
# Increase the test size to 40 percent
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.4, random_state=42)
# 1. Set up the model
model = LinearRegression()
# 2. Use fit
model.fit(X_train, y_train)
# 3. Check the score
model.score(X_test, y_test)
# Increase the test size to 50 percent and after 50 percent the score start decreasing
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.5, random_state=42)
# 1. Set up the model
model = LinearRegression()
# 2. Use fit
model.fit(X_train, y_train)
# 3. Check the score
model.score(X_test, y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14065762004175367, 'fraction_numerical': 0.02374739039665971, 'mean_word_length': 6.259469696969697, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '333964', 'license': 'MIT', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1327, 'n_words': 370, 'path': 'Diabetes/Diabetes.ipynb', 'repo_name': 'LastAncientOne/Kaggle-Project', 'size': '3832'}