<jupyter_start><jupyter_text>Data<jupyter_code>df_aus = pd.read_csv("australia_cleaned.csv")
df_aus.drop(columns=['Unnamed: 0'],inplace=True)
df_aus.head()
df_aus.shape<jupyter_output><empty_output><jupyter_text>K-NN Regression for Temperature  Create Train and Test set<jupyter_code>#considering only relative humidity and windspeed
X_temp=df_aus.drop(columns=['Maximum Temperature','Minimum Temperature','Temperature','Precipitation',
                            'Name','Date time','Cloud Cover','Visibility'],axis=1)
Y_temp=df_aus.Temperature
from sklearn.model_selection import train_test_split
train_X_temp,test_X_temp,train_y_temp,test_y_temp = train_test_split(X_temp,Y_temp,test_size=0.35,shuffle=False)
train_X_temp.head()<jupyter_output><empty_output><jupyter_text>Preprocessing – Scaling the features<jupyter_code>from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import MinMaxScaler
x_scaled= MinMaxScaler()
train_X_temp[['Wind Speed','Relative Humidity']] = x_scaled.fit_transform(train_X_temp[['Wind Speed','Relative Humidity']])

x_test_scaled= MinMaxScaler()
test_X_temp[['Wind Speed','Relative Humidity']]=x_test_scaled.fit_transform(test_X_temp[['Wind Speed','Relative Humidity']])
train_X_temp.shape
test_X_temp.shape<jupyter_output><empty_output><jupyter_text>Implementing RandomizedSearchCV  For Decision Tree<jupyter_code>#Note: Max_depth can be done
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import RandomizedSearchCV
from sklearn.model_selection import GridSearchCV
dc= DecisionTreeRegressor(random_state=1234)
params = {'max_features': ['auto', 'sqrt', 'log2'],
          'min_samples_split': [2,3,4,5,6,7,8,9,10,11,12,13,14,15], 
          'min_samples_leaf':[1,2,3,4,5,6,7,8,9,10,11],
          'max_depth':[i for i in range(1,15)]}
#Making models with hyper parameters sets
dc = RandomizedSearchCV(dc, param_distributions=params,cv=8, n_jobs=-1)
#Learning
dc.fit(train_X_temp,train_y_temp)
#The best hyper parameters set
print("Best Hyper Parameters:",dc.best_params_)<jupyter_output>Best Hyper Parameters: {'min_samples_split': 15, 'min_samples_leaf': 4, 'max_features': 'auto', 'max_depth': 7}<jupyter_text>For Knn<jupyter_code>from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import RandomizedSearchCV
knn = KNeighborsRegressor()
params = {'n_neighbors':[i for i in range(5,20)],
         'leaf_size':[1,2,3,5],
          'weights':['uniform', 'distance'],
          'algorithm':['auto', 'ball_tree','kd_tree','brute'],
          'n_jobs':[-1]}


knn = RandomizedSearchCV(knn,param_distributions=params,cv=8)
knn.fit(train_X_temp,train_y_temp)
knn.best_params_<jupyter_output><empty_output><jupyter_text>For SVM<jupyter_code>from sklearn import svm
#making the instance
svm_r=svm.SVR()
#Hyper Parameters Set
params = {'C': [6,7,8,9,10,11,12], 
          'kernel': ['linear','rbf']}
#Making models with hyper parameters sets
svm_r = RandomizedSearchCV(svm_r, param_distributions=params,cv=10, n_jobs=-1)
#Learning
svm_r.fit(train_X_temp,train_y_temp)
#The best hyper parameters set
print("Best Hyper Parameters:\n",svm_r.best_params_)<jupyter_output>Best Hyper Parameters:
 {'kernel': 'rbf', 'C': 12}
{'fraction_non_alphanumeric': 0.1329605467536502, 'fraction_numerical': 0.023609816713264987, 'mean_word_length': 8.147727272727273, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '70912', 'license': 'MIT', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1147, 'n_words': 194, 'path': 'Reports/Regression/Australia/.ipynb_checkpoints/Australia_regression_Hyper_parameter_tuning-checkpoint.ipynb', 'repo_name': 'SFLazarus/731_Final_Project', 'size': '3219'}