<jupyter_start><jupyter_text>- <NAME> - Parveen - <NAME><jupyter_code>import numpy as np 
import pandas as pd 
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import sklearn
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error
from sklearn.metrics import r2_score
from sklearn.preprocessing import  LabelEncoder
%matplotlib inline
df = pd.read_csv(r"D:Final WM Data.csv")
df.head()
df.drop('Unnamed: 0', inplace=True, axis=1)
df.WashingMethod.unique()
df.info()
cor = df.corr()
plt.figure(figsize=(11,7))
sns.heatmap(cor, annot=True)
plt.show()
df.Dryer.unique()
df.nunique()
label_Ftype = LabelEncoder()
label_WashingMethod=LabelEncoder()

df['FType'] = label_Ftype.fit_transform(df['FType'])
df['WashingMethod'] = label_WashingMethod.fit_transform(df['WashingMethod'])
df['Load'] = df['Load'].replace({'Front Load': 1, 'Top Load':0})
df['Dryer'] = df['Dryer'].replace({'No Dryer': 0, 'Spin Dry':1,'Air Dry':2})
df['Built_In_Heater'] = df['Built_In_Heater'].replace({'No': 0, 'Yes':1})
df.head()
display(df.describe().round(2))
cor = df.corr()
plt.figure(figsize=(11,7))
sns.heatmap(cor, annot=True)
plt.show()
dt = pd.get_dummies(df, columns=['Brand'])
dt<jupyter_output><empty_output><jupyter_text>Splitting:<jupyter_code>x = dt.drop(['Price','Name','Model'], axis=1)
y = dt['Price']
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size = 0.3)<jupyter_output><empty_output><jupyter_text>Random Forest Regression:<jupyter_code>from sklearn.ensemble import RandomForestRegressor
rfr = RandomForestRegressor(n_estimators=20)
rfr.fit(x_train , y_train)
#accuracies = cross_val_score(estimator = rfr, x = x_train, y = y_train, cv = 5,verbose = 1)
y_pred = rfr.predict(x_test)
print('')
print('###### Random Forest ######')
print('Score : %.4f' % rfr.score(x_test, y_test))
#print(accuracies)
r2 = r2_score(y_test, y_pred)
print('R2     : %0.2f ' % r2)
print('Score : %.4f' % rfr.score(x_train, y_train))
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import GridSearchCV

params = {
    "n_estimators":[10,20,30,40,50],
    'min_samples_split': [2,3,4,5],
    'min_samples_leaf': [1, 2, 5],
    'max_depth': [15,17,21,22]
}
rfr = RandomForestRegressor()
rfr= GridSearchCV(rfr, params, scoring="neg_root_mean_squared_error", n_jobs=-1, verbose=1, cv=3)
rfr.fit(x_train, y_train)
best_params = rfr.best_params_
print(f"Best paramters: {best_params})")
rfr = RandomForestRegressor(n_estimators=20,max_depth=15, min_samples_leaf=2, min_samples_split= 3)
rfr.fit(x_train , y_train)
#accuracies = cross_val_score(estimator = rfr, x = x_train, y = y_train, cv = 5,verbose = 1)
y_pred = rfr.predict(x_test)
print('')
print('###### Random Forest ######')
print('Score : %.4f' % rfr.score(x_test, y_test))
#print(accuracies)
import graphviz
from sklearn import tree
from sklearn.tree import export_graphviz
estimator = rfr.estimators_[19]
dot_data = tree.export_graphviz(estimator, out_file=None, filled=True, rounded=True,
                                feature_names=x_train.columns,  
                                )
graph =  graphviz.Source(dot_data)
graph<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15682656826568267, 'fraction_numerical': 0.02183271832718327, 'mean_word_length': 6.35972850678733, 'pattern_counts': {'":': 1, '<': 15, '<?xml version=': 0, '>': 15, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '590613', 'license': 'Apache-2.0', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1246, 'n_words': 235, 'path': 'GAN Model/Team A -WM Models-RF.ipynb', 'repo_name': 'MrTONYCHAN/xyz', 'size': '3271'}