<jupyter_start><jupyter_text>**ENERGY METER USING ML** Loading Dataset<jupyter_code>from pandas import read_csv
from google.colab import files
uploaded = files.upload()
fileName = "Energy Meter.csv"
names = ['Voltage','Current','Power','class']
dataset = read_csv(fileName, names=names)<jupyter_output><empty_output><jupyter_text>Summarize Dataset:<jupyter_code>print(dataset.shape)
print(dataset.head(20))
print(dataset.describe())
print(dataset.groupby('class').size())<jupyter_output>(400, 4)
    Voltage  Current  Power   class
0    0.0000      0.0    0.0  NoLoad
1    0.0000      0.0    0.0  NoLoad
2    0.0000      0.0    0.0  NoLoad
3    0.0000      0.0    0.0  NoLoad
4    0.0000      0.0    0.0  NoLoad
5    0.0000      0.0    0.0  NoLoad
6    0.0000      0.0    0.0  NoLoad
7    0.3833      0.0    0.0  NoLoad
8    0.0000      0.0    0.0  NoLoad
9    0.0000      0.0    0.0  NoLoad
10   0.0000      0.0    0.0  NoLoad
11   0.0000      0.0    0.0  NoLoad
12   0.0000      0.0    0.0  NoLoad
13   0.0000      0.0    0.0  NoLoad
14   0.0000      0.0    0.0  NoLoad
15   0.0000      0.0    0.0  NoLoad
16   0.0000      0.0    0.0  NoLoad
17   0.0000      0.0    0.0  NoLoad
18   0.0000      0.0    0.0  NoLoad
19   0.0000      0.0    0.0  NoLoad
          Voltage     Current       Power
count  400.000000  400.000000  400.000000
mean   160.657320    0.317734   68.065053
std     93.125536    0.320430   68.941682
min      0.000000    0.000000    0.000000
25%     79.151450    0.07[...]<jupyter_text>Visualize Dataset<jupyter_code>from pandas.plotting import scatter_matrix
from matplotlib import pyplot
dataset.plot(kind='bar',subplots=True,layout=(2,2))
pyplot.title('BAR PLOT')
pyplot.show()
dataset.hist()
pyplot.title('HISTOGRAM PLOT')
pyplot.show()
  
scatter_matrix(dataset)
pyplot.title('SCATTER PLOT')
pyplot.show()<jupyter_output><empty_output><jupyter_text>Evaluating various ML Algorithm<jupyter_code># 6 ML algorithms
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC


from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import StratifiedKFold
array = dataset.values
X = array[:,0:3]
y = array[:,3]
X_train, X_validation, Y_train, Y_validation = train_test_split(X, y, test_size=0.20, random_state=1, shuffle=True)
models = []
models.append(('LR', LogisticRegression(solver='liblinear', multi_class='ovr')))
models.append(('LDA', LinearDiscriminantAnalysis()))
models.append(('KNN', KNeighborsClassifier()))
models.append(('CART', DecisionTreeClassifier()))
models.append(('NB', GaussianNB()))
models.append(('SVM', SVC(gamma='auto')))
results = []
names = []
res = []
print('Acuracy For Different Algorithms')
for name, model in models:
  kfold = StratifiedKFold(n_splits=10, random_state=None)
  cv_results = cross_val_score(model, X_train, Y_train,cv = kfold,scoring ='accuracy')
  results.append(cv_results)
  names.append(name)
  res.append(cv_results.mean())
  
  print('%s:%f' % (name, cv_results.mean()))


pyplot.bar(names, res)
res = pyplot.gca()
res.set_ylim([0.990, 0.999])
pyplot.show()<jupyter_output><empty_output><jupyter_text>Saving Model and Predicting result for given values<jupyter_code>model = SVC(gamma='auto')

model.fit(X_train, Y_train)

import pickle
filename = 'finalized_model.pkl'
pickle.dump(model, open(filename, 'wb'))

loaded_model = pickle.load(open(filename, 'rb'))
result = loaded_model.score(X_validation, Y_validation)
print(result)

value = [[212.7315,0.84753,180.2963282]]
predictions = loaded_model.predict(value)
print(predictions[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12103896103896104, 'fraction_numerical': 0.09558441558441559, 'mean_word_length': 3.8932655654383734, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '96802', 'license': 'Apache-2.0', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1440, 'n_words': 308, 'path': 'EnergyMeter.ipynb', 'repo_name': 'Meera9373/EnergyMeter', 'size': '3850'}