<jupyter_start><jupyter_text>Importing Necessary libraries<jupyter_code>import numpy as np
import pandas as pd
 
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
from sklearn.ensemble import RandomForestRegressor
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import mean_squared_error, r2_score<jupyter_output><empty_output><jupyter_text>Making a Random Forest Regressor Model<jupyter_code>dataset_url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv'
data = pd.read_csv(dataset_url,delimiter =';')
 
#Split data into training and test sets
y = data.quality
X = data.drop('quality', axis=1)
X_train, X_test, y_train, y_test = train_test_split(X, y, 
                                                    test_size=0.3, 
                                                    random_state=123, 
                                                    stratify=y)
 
# Declaring data preprocessing steps
pipeline = make_pipeline(preprocessing.StandardScaler(), 
                         RandomForestRegressor(n_estimators=100))
 
#Declare hyperparameters to tune
hyperparameters = { 'randomforestregressor__max_features' : ['auto', 'sqrt', 'log2'],
                  'randomforestregressor__max_depth': [None, 5, 3, 1]}
 
#Tune model using cross-validation pipeline
clf = GridSearchCV(pipeline, hyperparameters, cv=20)
 
clf.fit(X_train, y_train)
 
#Evaluate model pipeline on test data
pred = clf.predict(X_test)
print(r2_score(y_test, pred))
print(mean_squared_error(y_test, pred))<jupyter_output>0.5572206324980478
0.34637972789115645<jupyter_text>Analysing the Data using Numpy<jupyter_code>#reading the data from csv file using numpy
wine = np.genfromtxt(dataset_url,delimiter=';',skip_header=1)
#printing the shape of wine
wine.shape
#displaying first 10 rows of the array
wine[:10,:]
#saving the data in float datatype
wine.astype(np.float)
#classifying the wine high in quality and alcohol content
high_quality_and_alcohol = (wine[:,10] > 10) & (wine[:,11] > 7)
wine[high_quality_and_alcohol,10:]
#modifying the array to a 1D array
wine.ravel()
#reshaping the array to 2x6 array
wine[1,:].reshape((2,6))
#loading the redwine dataset
dataset_red = 'https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv'
winered = np.genfromtxt(dataset_red,delimiter=';',skip_header=1)
#displaying the shape of winered
winered.shape
# combining the red and white wine vertically
all_wines = np.vstack((wine,winered))
#combining both red and white wine using concate function
np.concatenate((wine,winered),axis=0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09523809523809523, 'fraction_numerical': 0.027316352897748246, 'mean_word_length': 4.4417670682730925, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '210020', 'license': 'MIT', 'n_tokens_mistral': 931, 'n_tokens_neox': 847, 'n_words': 206, 'path': 'Task2/Pratiksha Shinde-Task2/Task_2.ipynb', 'repo_name': 'pratiksha-shinde123/ML', 'size': '2709'}