<jupyter_start><jupyter_text>Using the Polynomial features and the Linear regression models to predict the clinician's motor updrs score taken from a telemonitoring device from sixteen different biomedical voice measures for patients with early stage parkinsons disease.<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

from sklearn.linear_model import LinearRegression
from sklearn.linear_model import ElasticNet
from sklearn.linear_model import Ridge, Lasso
from sklearn.linear_model import SGDRegressor
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler, PolynomialFeatures
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
from yellowbrick.regressor import ResidualsPlot
from sklearn.decomposition import PCA<jupyter_output><empty_output><jupyter_text>**Reading dataset into the python environment**<jupyter_code>p_dataset= pd.read_csv("/content/parkinsons_updrs.data",sep = ",")
p_dataset<jupyter_output><empty_output><jupyter_text>**Dropping unnecessary columns**<jupyter_code>new_p_dataset = p_dataset.drop(columns=['subject#','total_UPDRS'])
new_p_dataset.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 5875 entries, 0 to 5874
Data columns (total 20 columns):
 #   Column         Non-Null Count  Dtype  
---  ------         --------------  -----  
 0   age            5875 non-null   int64  
 1   sex            5875 non-null   int64  
 2   test_time      5875 non-null   float64
 3   motor_UPDRS    5875 non-null   float64
 4   Jitter(%)      5875 non-null   float64
 5   Jitter(Abs)    5875 non-null   float64
 6   Jitter:RAP     5875 non-null   float64
 7   Jitter:PPQ5    5875 non-null   float64
 8   Jitter:DDP     5875 non-null   float64
 9   Shimmer        5875 non-null   float64
 10  Shimmer(dB)    5875 non-null   float64
 11  Shimmer:APQ3   5875 non-null   float64
 12  Shimmer:APQ5   5875 non-null   float64
 13  Shimmer:APQ11  5875 non-null   float64
 14  Shimmer:DDA    5875 non-null   float64
 15  NHR            5875 non-null   float64
 16  HNR            5875 non-null   float64
 17  RPDE           5875 non-null   float64
 18  DFA     [...]<jupyter_text>**checking for missing values**<jupyter_code>new_p_dataset.isna().sum()<jupyter_output><empty_output><jupyter_text>**checking for outliers using the describe function**<jupyter_code>new_p_dataset.describe()<jupyter_output><empty_output><jupyter_text>**Fixing outliers**<jupyter_code>new_p_dataset['age'] = np.where(new_p_dataset['age'] < 58.000000, 65.000000, new_p_dataset['age'])
new_p_dataset['Jitter(%)'] = np.where(new_p_dataset['Jitter(%)'] > 0.006800, 0.004900, new_p_dataset['Jitter(%)'])
new_p_dataset['Jitter(Abs)'] = np.where(new_p_dataset['Jitter(Abs)'] > 0.000053, 0.000035, new_p_dataset['Jitter(Abs)'])
new_p_dataset['Jitter:RAP'] = np.where(new_p_dataset['Jitter:RAP'] > 0.003290, 0.002250, new_p_dataset['Jitter:RAP'])
new_p_dataset['Jitter:PPQ5'] = np.where(new_p_dataset['Jitter:PPQ5'] > 0.003460, 0.002490, new_p_dataset['Jitter:PPQ5'])
new_p_dataset['Jitter:DDP'] = np.where(new_p_dataset['Jitter:DDP'] > 0.009870, 0.006750, new_p_dataset['Jitter:DDP'])
new_p_dataset['Shimmer'] = np.where(new_p_dataset['Shimmer'] > 0.039750, 0.027510, new_p_dataset['Shimmer'])
new_p_dataset['Shimmer(dB)'] = np.where(new_p_dataset['Shimmer(dB)'] > 0.365000, 0.253000, new_p_dataset['Shimmer(dB)'])
new_p_dataset['Shimmer:APQ3'] = np.where(new_p_dataset['Shimmer:APQ3'] > 0.020575, 0.013700, new_p_dataset['Shimmer:APQ3'])
new_p_dataset['Shimmer:APQ5'] = np.where(new_p_dataset['Shimmer:APQ5'] > 0.023755, 0.015940, new_p_dataset['Shimmer:APQ5'])
new_p_dataset['Shimmer:APQ11'] = np.where(new_p_dataset['Shimmer:APQ11'] > 0.032715, 0.022710, new_p_dataset['Shimmer:APQ11'])
new_p_dataset['Shimmer:DDA'] = np.where(new_p_dataset['Shimmer:DDA'] > 0.061735, 0.041110, new_p_dataset['Shimmer:DDA'])
new_p_dataset['NHR'] = np.where(new_p_dataset['NHR'] > 0.031463, 0.018448, new_p_dataset['NHR'])
new_p_dataset['HNR'] = np.where(new_p_dataset['HNR'] > 24.444000, 21.920000, new_p_dataset['HNR'])
new_p_dataset['HNR'] = np.where(new_p_dataset['HNR'] < 19.406000, 21.920000, new_p_dataset['HNR'])
new_p_dataset['RPDE'] = np.where(new_p_dataset['RPDE'] > 0.614045, 0.542250, new_p_dataset['RPDE'])
new_p_dataset['RPDE'] = np.where(new_p_dataset['RPDE'] < 0.469785, 0.542250, new_p_dataset['RPDE'])
new_p_dataset['PPE'] = np.where(new_p_dataset['PPE'] > 0.264490, 0.205500, new_p_dataset['PPE'])<jupyter_output><empty_output><jupyter_text>**checking for the relationship between variables**<jupyter_code>plt.figure(figsize=(17,12))
sns.heatmap(new_p_dataset.corr(), annot=True)<jupyter_output><empty_output><jupyter_text>**splitting dataset into dependent and independent variables**<jupyter_code>y = new_p_dataset['motor_UPDRS']
x = new_p_dataset.drop(['motor_UPDRS','Jitter:DDP','Shimmer:DDA','Shimmer:APQ5','RPDE','Jitter(%)','Jitter:RAP','Shimmer','Shimmer(dB)','Shimmer:APQ11','HNR','PPE'], axis =1)
plt.figure(figsize=(17,12))
sns.heatmap(x.corr(), annot=True)<jupyter_output><empty_output><jupyter_text>**checking for multicollinearity**<jupyter_code>from statsmodels.stats.outliers_influence import variance_inflation_factor
def calcu_mult(df):
  vif = pd.DataFrame()
  vif["variables"] = x.columns
  vif["VIF"] = [variance_inflation_factor(x.values, i) for i in range(x.shape[1])]

  return vif
calcu_mult(x)<jupyter_output><empty_output><jupyter_text>**Splitting the dataset into train and test and then redoing the split for validation test**<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=.20, random_state=45)<jupyter_output><empty_output><jupyter_text>**splitting normalized dataset into validation**<jupyter_code>normal_data = MinMaxScaler()
scaler = pd.DataFrame(normal_data.fit_transform(X_train))
X_train_, X_val, y_train_, y_val = train_test_split(scaler, y_train, test_size=0.25, random_state=1)<jupyter_output><empty_output><jupyter_text>Depicting dimensionality reduction techniques using Random Forest.This shows the important variables that affect the dependent variable.All other variables should be dropped if found unimportant.<jupyter_code>model = RandomForestRegressor(random_state=1, max_depth=4)
model.fit(X_train_, y_train_)
features = scaler.columns
importances = model.feature_importances_
indices = np.argsort(importances)[-8:]
plt.title('Feature Importances')
plt.barh(range(len(indices)), importances[indices], color='b', align='center')
plt.yticks(range(len(indices)), [features[i] for i in indices])
plt.xlabel('Relative Importance')
plt.show()
ln_features_ = PolynomialFeatures(degree = 6, include_bias=False)
model_fit_ = ln_features_.fit_transform(scaler)
ln_features_x = ln_features_.fit_transform(X_test)
ln_model = LinearRegression()
ln_result = ln_model.fit(model_fit_, y_train)
ln_result.score(model_fit_, y_train)
1 - (1-ln_result.score(model_fit_,y_train))*(len(y_train)-1)/(len(y_train)-model_fit_.shape[1]-1)
intercept = ln_result.coef_
intercept
y_predict =ln_result.predict(ln_features_x)
y_predict<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13450616428868264, 'fraction_numerical': 0.06316664357944314, 'mean_word_length': 6.796976241900648, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '585589', 'license': 'MIT', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2664, 'n_words': 462, 'path': 'Predicting_Parkingsons.ipynb', 'repo_name': 'mojoyinkimberly/Predicting_Parkinsons', 'size': '7219'}