<jupyter_start><jupyter_text>Loading and viewing the Dataset<jupyter_code>df=pd.read_csv('insurance.csv')
df.head()<jupyter_output><empty_output><jupyter_text>Performing one hot encoding on columns and removinf NAN values(if any)<jupyter_code>df=pd.get_dummies(df)
len(df)
len(df.dropna())<jupyter_output><empty_output><jupyter_text>Defining Accuracy Function<jupyter_code>def accuracy(y_pred,y_test):
    from sklearn import metrics
    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd
    print("MAE",metrics.mean_absolute_error(y_test,y_pred))
    print("RMSE",np.sqrt(metrics.mean_squared_error(y_test,y_pred)))    # using heatmap to plot accuracy
    plt.scatter(y_test,y_pred)
    plt.xlabel('predicted values')
    plt.ylabel('true values')
    plt.show()<jupyter_output><empty_output><jupyter_text>Split into training ans testing dataset<jupyter_code>y=df['charges']
x=df.drop(columns=['charges'])
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,shuffle=True)<jupyter_output><empty_output><jupyter_text>1)Using Random Forest Regression<jupyter_code>#Random Forest Regressor
from sklearn.ensemble import RandomForestRegressor
regressor=RandomForestRegressor(n_estimators=100,random_state=0)
regressor.fit(x_train,y_train)
y_pred_randf=regressor.predict(x_test)<jupyter_output><empty_output><jupyter_text>2)Using SGD Regression<jupyter_code>from sklearn.linear_model import SGDRegressor
clf=SGDRegressor(max_iter=1000,tol=1e-3)
clf.fit(x,y)
y_pred_sgd=clf.predict(x_test)<jupyter_output><empty_output><jupyter_text>3)Using Lasso Regression<jupyter_code>#Lasso Regression
from sklearn.linear_model import Lasso
lasso=Lasso(alpha=100)
lasso.fit(x_train,y_train)
y_pred_lasso=lasso.predict(x_test)<jupyter_output>C:\Users\<NAME>\Anaconda3\lib\site-packages\sklearn\linear_model\coordinate_descent.py:492: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.
  ConvergenceWarning)<jupyter_text>4)Using Elastic net Regression<jupyter_code>#ElasticNet Regession
from sklearn.linear_model import ElasticNet
model=ElasticNet()
model.fit(x_train,y_train)
y_pred_elastic=model.predict(x_test)<jupyter_output>C:\Users\<NAME>\Anaconda3\lib\site-packages\sklearn\linear_model\coordinate_descent.py:492: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.
  ConvergenceWarning)<jupyter_text>5)Using Support Vector Regression<jupyter_code>from sklearn import svm
clf = svm.SVR(kernel='rbf')
clf.fit(x,y)
y_pred_svr=clf.predict(x_test)
print("Random Forest")
accuracy(y_pred_randf,y_test)
print("SGD Regression")
accuracy(y_pred_sgd,y_test)
print("Lasso Regression")
accuracy(y_pred_lasso,y_test)
print("Elastic Net Regression")
accuracy(y_pred_elastic,y_test)
print("SVR Regression")
accuracy(y_pred_svr,y_test)<jupyter_output>Random Forest
MAE 2321.122070847836
RMSE 3976.5750678703776
{'fraction_non_alphanumeric': 0.10194174757281553, 'fraction_numerical': 0.019093851132686083, 'mean_word_length': 9.621993127147766, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '565225', 'license': 'MIT', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1125, 'n_words': 183, 'path': 'Regression/(3) Medical Cost Personal Dataset/Medical-Cost-Personal-Dataset.ipynb', 'repo_name': 'Kashyap85/Machine-Learning-101', 'size': '3100'}