<jupyter_start><jupyter_text>VALCANOS DATASET<jupyter_code>import os
import pandas as pd
%pwd
%cd C:\Users\Administrator\Documents\datasets<jupyter_output>C:\Users\Administrator\Documents\datasets<jupyter_text>Step 1: checking the initial data information<jupyter_code>import pandas as pd
df=pd.read_csv('Valcanoes.csv',sep=",")
df.head()
df.tail()
df.shape
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 1252 entries, 0 to 1251
Data columns (total 4 columns):
V1       1252 non-null int64
V2       1252 non-null int64
V3       1252 non-null float64
Class    1252 non-null int64
dtypes: float64(1), int64(3)
memory usage: 39.2 KB<jupyter_text>From the above data we find that the  V1,V2,V3,Class are the numerical data<jupyter_code>df.isnull().sum()<jupyter_output><empty_output><jupyter_text>there is no missing values<jupyter_code>vol=df
vol.head()
vol['Class'].unique()
vol.describe()
vol["V1"].median()
vol["V2"].median()
vol["V3"].median()
vol["Class"].median()
vol.groupby("V1")["Class"].describe()
vol.groupby("V1")["Class"].value_counts()
# variance of the data
vol.var()<jupyter_output><empty_output><jupyter_text>the Variance of the data set<jupyter_code>normed_val = (vol - vol.min()) / (vol.max() - vol.min())
normed_val.head(5)
normed_val.describe()
normed_val.var()
boxplot = df.boxplot(column=['V1','V2','V3'], by='Class',layout=(3, 1))
import matplotlib.pyplot as plt
normed_val.V1.hist()
plt.title('Histogram of V1')
plt.xlabel('Class')
plt.ylabel('V1')
import matplotlib.pyplot as plt
normed_val.V2.hist()
plt.title('Histogram of V2')
plt.xlabel('Class')
plt.ylabel('V2')
import matplotlib.pyplot as plt
normed_val.V3.hist()
plt.title('Histogram of V3')
plt.xlabel('Class')
plt.ylabel('V3')<jupyter_output><empty_output><jupyter_text>Step2: Perform classification  LOGISTIC REGRESSION<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
X = vol.iloc[:, :-1]
y = vol.iloc[:, -1]
from sklearn.model_selection import train_test_split 
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, 
                                                    random_state=1)
from sklearn.linear_model import LogisticRegression 
from sklearn.metrics import accuracy_score 
model = LogisticRegression()

#model.fit(X, y)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
accuracy=accuracy_score(y_test,y_pred)
print(accuracy)
from sklearn.metrics import confusion_matrix
cnf_matrix = confusion_matrix(y_test, y_pred)
cnf_matrix
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           1       0.91      1.00      0.95       567
           2       0.00      0.00      0.00         7
           3       0.00      0.00      0.00        11
           4       0.00      0.00      0.00        31
           5       0.00      0.00      0.00        10

   micro avg       0.91      0.91      0.91       626
   macro avg       0.18      0.20      0.19       626
weighted avg       0.82      0.91      0.86       626<jupyter_text>Logistic Regression Converted the Class output  into 0 or 1<jupyter_code>normed_val.head()
normed_val["Class_1"]=[ 1 if x>=0.5 else 0 for x in normed_val["Class"]]
normed_val["Class_1"].head()
normed_val1=normed_val.drop(['Class'],axis=1)
normed_val1.head()

normed_val1["Class_1"].value_counts()
X = normed_val.iloc[:, :-1]
y = normed_val.iloc[:, -1]
from sklearn.model_selection import train_test_split 
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, 
                                                    random_state=1)
from sklearn.linear_model import LogisticRegression 
from sklearn.metrics import accuracy_score 
model = LogisticRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
accuracy=accuracy_score(y_test,y_pred)
print(accuracy)
from sklearn.metrics import confusion_matrix
cnf_matrix = confusion_matrix(y_test, y_pred)
cnf_matrix
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))
import seaborn as sns
vol_cm=pd.DataFrame(cnf_matrix,range(1,3),range(1,3))
vol_cm
sns.set(font_scale=1.6)
sns.heatmap(vol_cm,annot=True,annot_kws={"size":14})<jupyter_output><empty_output><jupyter_text>Neural Networks<jupyter_code>X1 = vol.iloc[:, :-1]
y1 = vol.iloc[:, -1]
from sklearn.model_selection import train_test_split 
X1_train, X1_test, y1_train, y1_test = train_test_split(X1, y1, test_size=0.5, 
                                                    random_state=1)
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score
model = MLPClassifier(hidden_layer_sizes=(20,10), max_iter=100)
model.fit(X1_train, y1_train)
y1_pred= model.predict(X1_test)
accuracy = model.score(X1_test,y1_test)
print(accuracy)
cnf_matrix = confusion_matrix(y1_test, y1_pred)
cnf_matrix
from sklearn.metrics import classification_report
print(classification_report(y1_test, y1_pred))<jupyter_output>precision    recall  f1-score   support

           1       0.91      1.00      0.95       567
           2       0.00      0.00      0.00         7
           3       0.00      0.00      0.00        11
           4       0.00      0.00      0.00        31
           5       0.00      0.00      0.00        10

   micro avg       0.90      0.90      0.90       626
   macro avg       0.18      0.20      0.19       626
weighted avg       0.82      0.90      0.86       626<jupyter_text>The neural network for the Normalized var 0 or 1<jupyter_code>normed_val1.head(5)
X2 = normed_val1.iloc[:, :-1]
y2 = normed_val1.iloc[:, -1]
from sklearn.model_selection import train_test_split 
X2_train, X2_test, y2_train, y2_test = train_test_split(X2, y2, test_size=0.5, 
                                                    random_state=1)
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score
model = MLPClassifier(hidden_layer_sizes=(20,30), max_iter=50)
model.fit(X2_train, y2_train)
y2_pred= model.predict(X2_test)
accuracy = model.score(X2_test,y2_test)
print(accuracy)
cnf_matrix = confusion_matrix(y2_test, y2_pred)
cnf_matrix
from sklearn.metrics import classification_report
print(classification_report(y2_test, y2_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.92      1.00      0.96       574
           1       0.00      0.00      0.00        52

   micro avg       0.92      0.92      0.92       626
   macro avg       0.46      0.50      0.48       626
weighted avg       0.84      0.92      0.88       626<jupyter_text>STEP-3 DIFFERENT NEURAL NETWORKS ACCURACY<jupyter_code>X1 = vol.iloc[:, :-1]
y1 = vol.iloc[:, -1]
from sklearn.model_selection import train_test_split 
X1_train, X1_test, y1_train, y1_test = train_test_split(X1, y1, test_size=0.5, 
                                                    random_state=1)
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score
model = MLPClassifier(hidden_layer_sizes=(200,225,250,275), max_iter=300)
model.fit(X1_train, y1_train)
y1_pred= model.predict(X1_test)
accuracy = model.score(X1_test,y1_test)
print(accuracy)
cnf_matrix = confusion_matrix(y1_test, y1_pred)
cnf_matrix
model = MLPClassifier(hidden_layer_sizes=(50,100,150,200,250,300,350,400), max_iter=1000)
model.fit(X1_train, y1_train)
y1_pred= model.predict(X1_test)
accuracy = model.score(X1_test,y1_test)
print(accuracy)
cnf_matrix = confusion_matrix(y1_test, y1_pred)
cnf_matrix
model = MLPClassifier(hidden_layer_sizes=(5,10), max_iter=20)
model.fit(X1_train, y1_train)
y1_pred= model.predict(X1_test)
accuracy = model.score(X1_test,y1_test)
print(accuracy)
cnf_matrix = confusion_matrix(y1_test, y1_pred)
cnf_matrix
import seaborn as sns
import matplotlib.pyplot as plt
vol_cm=pd.DataFrame(cnf_matrix,range(1,6),range(1,6))
vol_cm
sns.set(font_scale=1.6)
sns.heatmap(vol_cm,annot=True,annot_kws={"size":14})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10845335003130871, 'fraction_numerical': 0.0646211646837821, 'mean_word_length': 3.4639463387367244, 'pattern_counts': {'":': 2, '<': 37, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 31, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '570810', 'license': 'Apache-2.0', 'n_tokens_mistral': 3170, 'n_tokens_neox': 2967, 'n_words': 586, 'path': 'valcanos.ipynb', 'repo_name': 'SriDedeepyaNandamuri/isme-bangalore-Oct-Nov-2019', 'size': '7985'}