Machine Problem 2
Something about data visualization using matplotlib.
DS100-1
3Q1920Info! Broken links? Email us at gtechphofficial@gmail.com
This requires class_grades.csv file in the same directory of the code.
Code:
import pandas as pd
#importing csv file
data = pd.read_csv('class_grades.csv')
#print(data)
#getting row with index of 4
data = data.iloc[5]
#print(data)
#convertion of pandas dataframe to numpy array
arr1 = data.to_numpy()[1:6]
arr = arr1.astype(np.float64)
name = data.to_numpy()[0]
#print(arr)
import matplotlib.pyplot as plt
%matplotlib inline
x = [1,2,3,4,5]
import numpy as np
model = np.polyfit(x,arr,1)
predict = np.poly1d(model)
x_lin_reg = range(1,6)
y_lin_reg = predict(x_lin_reg)
plt.scatter(x, arr, c='black')
plt.plot(x_lin_reg, y_lin_reg, c='r')
plt.ylim(1,5)
plt.ylim(0,100)
plt.title(name + " " + str(arr1))
pc = np.corrcoef(x, arr)[0, 1]
print("Pearson coefficient = %s" % str(pc))