<jupyter_start><jupyter_text>1. sepal length in cm2. sepal width in cm3. petal length in cm4. petal width in cm5. class:-- Iris Setosa-- Iris Versicolour-- Iris Virginica<jupyter_code>df = pd.DataFrame(data=np.c_[data1['data'], data1['target']], 
             columns = data1['feature_names'] + ['target'])
df.head(25)
df.describe()<jupyter_output><empty_output><jupyter_text>Provides basic statistical details including the mean, percentile, quartiles, standard deviation, count, minimum, and maximum values of the data set.<jupyter_code>sns.pairplot(df, hue = 'target', height = 1.5)<jupyter_output><empty_output><jupyter_text>I implemented the pairplot as I wanted to see how the data was distributed. The pairplot plots pairwise relationships in a dataset and displays a grid of axes so each variable in the data frame is shown with respect to the y-axis and x-axis. In this case, the targets represent different flower species. The pairplot is useful here because there are few features. This would not be as effective for a high dimensional data set (that employs various types of features).<jupyter_code>df.plot(kind="hist")
df.columns
# Separate the dependent and independent features
X = df[['sepal length (cm)','sepal width (cm)',
           'petal length (cm)', 'petal width (cm)']]
y = df['target']
# target variable is just the y or the output variable
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 1)
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X)
X = scaler.transform(X)<jupyter_output><empty_output><jupyter_text>Standardization is the process of shifting the distribution of each attribute to have a mean of zero and a St. Dev. of one. This is a helpful method for attributes for a model because Standardization of datasets is performed before many machine learning estimators implemented in scikit-learn. If this is not done, they may behave badly as the individual features "do not more or less look like standard normally distributed data."  Linear Support Vector Machine<jupyter_code>from sklearn.svm import SVC
from sklearn import metrics
svc = SVC(kernel = 'linear') #Default hyperparameters
svc.fit(X_train, y_train)
y_pred = svc.predict(X_test)
print('Accuracy Score:')
print(metrics.accuracy_score(y_test, y_pred))
# RMSE determines root mean square deviation
# common metric for evaluating quality of predictions & shows how far predictions fall from
# true measured values (when we apply Euc. dist.)
from sklearn.metrics import mean_squared_error

# Compute MSE using MSE ^ (1/2)
mse = mean_squared_error(y_test, y_pred)
print("Mean Squared Error: ", mse)

# Calculate the root mean squared error
# Computes the mean of the distances b/w the actual values and the predicted values
# Highlights the importance of some of the errors

from math import sqrt
rmse = sqrt(mse)
print("RMSE: ", round((rmse), 3))
from sklearn.model_selection import cross_val_score
svc = SVC(kernel = 'rbf')
# radial basis function kernel
# computes squared euclidean distance b/w 2 feature vectors
score = cross_val_score(svc, X, y, cv = 10, scoring = 'accuracy')
print(score)
print(score.mean())
# Tune SVM hyperparameters by using GridSearchCV with cross validation.
from sklearn.model_selection import GridSearchCV
# Now I create a dictionary to pass the values into the GridSearchCV 
# this is necessary for the param_grid parameter
# tuning helps us find the best parameter that gives us the best possible score
param_list = {"C": [1, 5, 10, 20, 50, 100],
             "gamma": [10, 1, 0.1, 0.01, 0.0001]
}
grid = GridSearchCV(SVC(), param_list, refit = True, verbose = 5)
# verbose = 5 which >3 as the fold & candidate parameter indices are shown together w/
# original begin time of the computation
from sklearn.neighbors import KNeighborsClassifier
classifier = KNeighborsClassifier(n_neighbors = 9)
knn = KNeighborsClassifier()
from sklearn.model_selection import RandomizedSearchCV
kvals = list(range(1, 100))
# supplies values into key value pairs for the requred dictionary
# that serves as an input for param_grid
pgrd = dict(n_neighbors = kvals)
rand = RandomizedSearchCV(knn, pgrd, cv = 10, scoring = 'accuracy',
                          n_iter = 10, random_state = 5)
rand.fit(X, y)

# displays the settings of the parameters that have been selected
rand.fit(X_train, y_train)
rand.cv_results_
print("The accuracy of the KNN model is as follows: ", rand.best_score_)
print(rand.best_params_)<jupyter_output>The accuracy of the KNN model is as follows:  0.9666666666666666
{'n_neighbors': 29}
{'fraction_non_alphanumeric': 0.08234788217587616, 'fraction_numerical': 0.016555579445280584, 'mean_word_length': 5.10498687664042, 'pattern_counts': {'":': 2, '<': 16, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '548955', 'license': 'MIT', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1360, 'n_words': 562, 'path': 'Iris Data Set.ipynb', 'repo_name': 'Dre1896/RIT-DSCI-633-FDS', 'size': '4651'}