<jupyter_start><jupyter_text>1. Box plot<jupyter_code>plt.boxplot(df['fixed acidity'])
df.boxplot(column='fixed acidity', by='quality')<jupyter_output><empty_output><jupyter_text>2. Histogram<jupyter_code># It is used for visulize the disribution numerical variable.
# An outlier will be the outside of overall pattern of distribution.
df['fixed acidity'].hist()
# Now you can say in above graph. This is the right skewed. Now you can check for other variables as well.<jupyter_output><empty_output><jupyter_text>3. Scatterplot<jupyter_code># Scatter plot viasulize the relationship in two quantitative variables.
# If the data outside from general clustering that is called outliers.
fig, ax = plt.subplots(figsize=(12, 6))
ax.scatter(df['quality'],df['fixed acidity'])
ax.set_xlabel("Fixed Acidity")
ax.set_ylabel("Quantity")
plt.show()<jupyter_output><empty_output><jupyter_text>Outliers Treatment<jupyter_code>## IQR Score (Q1 - 1.5 IQR) and (Q3 + 1.5 IQR)
df_out = df[~((df < (Q1 - 1.5 * IQR)) |(df > (Q3 + 1.5 * IQR))).any(axis=1)]
print(df_out.shape)
plt.boxplot(df_out['fixed acidity'])
df_out['fixed acidity'].hist()<jupyter_output><empty_output><jupyter_text>Feature Selection<jupyter_code># 1. Reduces Overfitting
# 2. Improves Accuracy
# 3. Reduces Traning Time<jupyter_output><empty_output><jupyter_text>Correlation Matrix with Heatmap<jupyter_code>import seaborn as sns
X = df_out.iloc[:,0:11]  #independent columns
y = df_out.iloc[:,-1]    #target column i.e price range
#get correlations of each features in dataset
corrmat = df_out.corr()
top_corr_features = corrmat.index
plt.figure(figsize=(20,12))

# plot heat map
g=sns.heatmap(df_out.corr(),annot=True,cmap="RdYlGn")
df_out = df_out.drop(['residual sugar', 'free sulfur dioxide'], axis=1)
from sklearn.model_selection import train_test_split
x = df_out.iloc[:, :-1]
y = df_out.iloc[:, -1]
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=0)<jupyter_output><empty_output><jupyter_text>Model Traning  1. Logistic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression
lr = LogisticRegression()
lr.fit(x_train, y_train)
y_predict = lr.predict(x_test)
# Measuring the model accuracy
score = lr.score(x_test, y_test)
print(score)<jupyter_output>0.6033898305084746<jupyter_text>2. Naive Bayes<jupyter_code>from sklearn.naive_bayes import GaussianNB
nb = GaussianNB()
nb.fit(x_train, y_train)
y_pred = nb.predict(x_test)
nb.score(x_test, y_test)<jupyter_output><empty_output><jupyter_text>3. Stochastic Gradient Descent<jupyter_code>from sklearn.linear_model import SGDClassifier
sgd = SGDClassifier(loss = 'modified_huber', shuffle=True, random_state=101)
sgd.fit(x_train, y_train)
y_pred = sgd.predict(x_test)
# accuracy_score(y_test, y_pred)
sgd.score(x_test, y_test)<jupyter_output><empty_output><jupyter_text>4. K-Nearest Neighbours<jupyter_code>from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors=15)
knn.fit(x_train, y_train)
y_perd = knn.predict(x_test)
knn.score(x_test, y_test)<jupyter_output><empty_output><jupyter_text>5. Random Forest<jupyter_code>from sklearn.ensemble import RandomForestClassifier
rfm = RandomForestClassifier(n_estimators=100, oob_score = True, n_jobs=1,
                            random_state=101, max_features = None, min_samples_leaf = 60)
rfm.fit(x_train, y_train)
y_perd = rfm.predict(x_test)
rfm.score(x_test, y_test)<jupyter_output><empty_output><jupyter_text>6. Support Vector Machine<jupyter_code>from sklearn.svm import SVC
svm = SVC(kernel="linear", C=0.025, random_state=101)
svm.fit(x_train, y_train)
y_pred = svm.predict(x_test)
svm.score(x_test, y_test)
# My Accuracy is very low now I am trying to improve accuracy of my model.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12095490716180371, 'fraction_numerical': 0.021485411140583555, 'mean_word_length': 7.342920353982301, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '545264', 'license': 'Apache-2.0', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1448, 'n_words': 293, 'path': '2-WineQuality/Classification-Red-Wine-Quality-Own.ipynb', 'repo_name': 'saurabhdscience/Data-Science-Portfolio', 'size': '3770'}