<jupyter_start><jupyter_text>Step 1) EDA<jupyter_code>df=pd.read_csv("solar.csv",sep=",")
df.head()
df.columns                       #Column Names
df.shape<jupyter_output><empty_output><jupyter_text>Number of Numerical or Categorical Values??<jupyter_code>df.info()                      # The Data is Categorical 
type('spot_distribution	')
df.dtypes<jupyter_output><empty_output><jupyter_text>There are no Numerical Columns to find variance but i found using categorical...<jupyter_code>import numpy as np
np.var(df)<jupyter_output><empty_output><jupyter_text>As there are no Numerical values, i found normalization based on categorical data<jupyter_code>def normalize(df):
    result = df.copy()
    for feature_name in df.columns:
        max_value = df[feature_name].max()
        min_value = df[feature_name].min()
        result[feature_name] = (df[feature_name] - min_value) / (max_value - min_value)
    return result
normalize(df)
from sklearn.preprocessing import OneHotEncoder
onehotencoder = OneHotEncoder(categorical_features = df)
df2 = onehotencoder.fit_transform(df).toarray()

df2=pd.DataFrame(df2)
df2.head(5)<jupyter_output><empty_output><jupyter_text>Step 2  Performance Classification<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import sklearn
df=pd.read_csv("solar.csv",sep=",")
df.head()
df['class'].value_counts()
df=pd.read_csv('solar.csv',sep=",")
df.head()<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>df=pd.read_csv('solar.csv')
x = df.iloc[:,[0,1,2,3,4,5,6,7,8,9,10,11]].values
y = df.iloc[:,12].values
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.25,random_state=0)
from sklearn.preprocessing import StandardScaler
sc_x= StandardScaler()
x_train=sc_x.fit_transform(x_train)
x_test=sc_x.transform(x_test)
from sklearn.linear_model import LogisticRegression
classifier=LogisticRegression(random_state=0)
classifier.fit(x_train,y_train)
x_test
y_pred=classifier.predict(x_test)
y_pred
predicted_class=classifier.predict(x_test)<jupyter_output><empty_output><jupyter_text>Accuracy of the Model in Logistic Regression is 0.78...<jupyter_code>accuracy = accuracy_score(y_test,predicted_class)
parameters = classifier.coef_
print(accuracy)<jupyter_output>0.7827715355805244<jupyter_text>Confusion Matrix<jupyter_code>from sklearn.metrics import confusion_matrix
cm=confusion_matrix(y_test,y_pred)
cm
from sklearn.metrics import classification_report
print(classification_report(y_test,predicted_class))
def fperc(matrix):
    FP = matrix.sum(axis=0) - np.diag(matrix)
    FN = matrix.sum(axis=1) - np.diag(matrix)
    TP = np.diag(matrix)
    TN = matrix.sum() - (FP + FN + TP)
    FP = FP.astype(float)
    FN = FN.astype(float)
    TP = TP.astype(float)
    TN = TN.astype(float)
    FPR = FP/(FP+TN) # FPR - False Positive Rate
    FNR = FN/(TP+FN) # FNR - False Negative Rate
    fr=np.vstack((FPR,FNR))
    fr=fr*100
    false_rate=pd.DataFrame(fr,columns=[1,2,3,4,5,6],index=['FPR(%)','FNR(%)'])
    print(false_rate)
fperc(cm)
from sklearn import metrics
import seaborn as sns
import matplotlib.pyplot as plt
import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
array = [[48,  0,  0,  0,  0,  0],
       [ 0, 34, 18,  0,  0,  0],
       [ 0, 16, 39,  2,  0,  0],
       [ 0,  2, 10,  3,  4,  0],
       [ 0,  0,  4,  2,  1,  0],
       [ 0,  0,  0,  0,  0, 84]]
df_cm2 = pd.DataFrame(array, index = [i for i in "123456"],
                  columns = [i for i in "123456"])
plt.figure(figsize = (5,7))
sn.heatmap(df_cm2, annot=True)<jupyter_output><empty_output><jupyter_text>Neural Networks<jupyter_code>from sklearn.neural_network import MLPClassifier
nnmodel = MLPClassifier(hidden_layer_sizes=(100,50))

nnmodel.fit(x_train,y_train)

nnpredicted_class=nnmodel.predict(x_test)<jupyter_output><empty_output><jupyter_text>Accuracy in Nueral Network Model is 0.76....<jupyter_code>accuracy_score(y_test,nnpredicted_class)
from sklearn.metrics import classification_report

print(classification_report(y_test,nnpredicted_class))

nn_cm=confusion_matrix(y_test, nnpredicted_class)

nn_cm
import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
array = [[47,  0,  0,  0,  1,  0],
       [ 0, 36, 15,  1,  0,  0],
       [ 0, 20, 30,  6,  1,  0],
       [ 0,  2,  7,  6,  4,  0],
       [ 0,  0,  3,  2,  2,  0],
       [ 0,  0,  0,  0,  0, 84]]
df_cm2 = pd.DataFrame(array, index = [i for i in "123456"],
                  columns = [i for i in "123456"])
plt.figure(figsize = (5,7))
sn.heatmap(df_cm2, annot=True)
def fperc_n(matrix):
    FP = matrix.sum(axis=0) - np.diag(matrix)
    FN = matrix.sum(axis=1) - np.diag(matrix)
    TP = np.diag(matrix)
    TN = matrix.sum() - (FP + FN + TP)
    FP = FP.astype(float)
    FN = FN.astype(float)
    TP = TP.astype(float)
    TN = TN.astype(float)
    FPR = FP/(FP+TN) # FPR - False Positive Rate
    FNR = FN/(TP+FN) # FNR - False Negative Rate
    fr=np.vstack((FPR,FNR))
    fr=fr*100
    false_rate=pd.DataFrame(fr,columns=[1,2,3,4,5,6],index=['FPR(%)','FNR(%)'])
    print(false_rate)
fperc_n(nn_cm)    # False Positive & False Negative Percentage for Neural Network
fperc(cm) # False Positive & False Negative Percentage for Logistic Regression<jupyter_output>1          2          3          4          5    6
FPR(%)  0.0   8.372093  15.238095   1.612903   1.538462  0.0
FNR(%)  0.0  34.615385  31.578947  84.210526  85.714286  0.0<jupyter_text>Neural Network with different Number of Layers<jupyter_code>nnmodel1 = MLPClassifier(hidden_layer_sizes=(100,50,20))
nnmodel1.fit(x_train,y_train)
nnpredicted_class1=nnmodel1.predict(x_test)<jupyter_output><empty_output><jupyter_text>Accuracy of Neural Network here is 0.76..... with different layers<jupyter_code>accuracy_score(y_test,nnpredicted_class1)<jupyter_output><empty_output><jupyter_text>Accuracy remains almost same compared to previous NN<jupyter_code>from sklearn.metrics import classification_report
print(classification_report(y_test,nnpredicted_class1))<jupyter_output>precision    recall  f1-score   support

           0       1.00      1.00      1.00        48
           1       0.62      0.67      0.65        52
           2       0.54      0.51      0.52        57
           3       0.38      0.32      0.34        19
           4       0.11      0.14      0.12         7
           5       1.00      1.00      1.00        84

    accuracy                           0.76       267
   macro avg       0.61      0.61      0.61       267
weighted avg       0.76      0.76      0.76       267<jupyter_text>Neural Networks with Change in Layer sizes<jupyter_code>nnmodel2 = MLPClassifier(hidden_layer_sizes=(100,30))
nnmodel2.fit(x_train,y_train)
nnpredicted_class2=nnmodel2.predict(x_test)
accuracy_score(y_test,nnpredicted_class2)
nnmodel3 = MLPClassifier(hidden_layer_sizes=(100,10))
nnmodel3.fit(x_train,y_train)
nnpredicted_class3=nnmodel3.predict(x_test)
accuracy_score(y_test,nnpredicted_class3)<jupyter_output>C:\Users\nsidd\Anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py:566: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (200) reached and the optimization hasn't converged yet.
  % self.max_iter, ConvergenceWarning)
{'fraction_non_alphanumeric': 0.1203564084989719, 'fraction_numerical': 0.0568882796435915, 'mean_word_length': 3.8478405315614617, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '124559', 'license': 'Apache-2.0', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2756, 'n_words': 540, 'path': 'FML solar.ipynb', 'repo_name': 'siddhu21/isme-bangalore-Oct-Nov-2019', 'size': '7295'}