import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
=(5,5))
plt.figure(figsize= [3,4,5,2,6]
x = [25,35,39,20,41]
y
plt.scatter(x,y)"Height in feet")
plt.xlabel("Weight in KG")
plt.ylabel("height-weight-scatterplot.eps", format='eps',transparent=True) plt.savefig(
= [0,1,2,3]
x = [0,1,2,3]
y
plt.scatter(x,y)'x')
plt.xlabel('y')
plt.ylabel("scatterplot-2.eps", format='eps',transparent=True) plt.savefig(
# plt.figure(fig)
= [0,1,2,3]
x = [0,1,2,3]
y ="Ordinary data")
plt.scatter(x,y,label4],[0],label="Outlier")
plt.scatter(['x')
plt.xlabel('y')
plt.ylabel(# plt.legend(loc=(1.04,0)
plt.legend()"scatterplot-3.eps", format='eps',transparent=True) plt.savefig(
The PostScript backend does not support transparency; partially transparent artists will be rendered opaque.
The PostScript backend does not support transparency; partially transparent artists will be rendered opaque.
from sklearn.linear_model import LinearRegression
= np.array(x).reshape((-1,1))
x = np.array(y).reshape((-1,1))
y = LinearRegression()
model
model.fit(x,y)= model.predict(x) prediction
plt.scatter(x,y)'x')
plt.xlabel('y')
plt.ylabel(="Learnt Model")
plt.plot(x,prediction,labelfor i in range(len(x)):
'r')
plt.plot([x[i],x[i]],[prediction[i],y[i]],
plt.legend()"linear-fit.eps", format='eps',transparent=True) plt.savefig(
The PostScript backend does not support transparency; partially transparent artists will be rendered opaque.
The PostScript backend does not support transparency; partially transparent artists will be rendered opaque.
= plt.subplots()
fig, ax = np.linspace(-10,10,100)
x = x[x<=0]
x = func(x)
y
= -7.2
val
plt.scatter([val],func(np.array([val])))'local minima', xy=(val, func(val)), xytext=(val, 1),
ax.annotate(=dict(facecolor='black', shrink=0.05))
arrowprops
plt.xticks([])
plt.yticks([]) plt.plot(x,y)
x
array([-10. , -9.7979798 , -9.5959596 , -9.39393939,
-9.19191919, -8.98989899, -8.78787879, -8.58585859,
-8.38383838, -8.18181818, -7.97979798, -7.77777778,
-7.57575758, -7.37373737, -7.17171717, -6.96969697,
-6.76767677, -6.56565657, -6.36363636, -6.16161616,
-5.95959596, -5.75757576, -5.55555556, -5.35353535,
-5.15151515, -4.94949495, -4.74747475, -4.54545455,
-4.34343434, -4.14141414, -3.93939394, -3.73737374,
-3.53535354, -3.33333333, -3.13131313, -2.92929293,
-2.72727273, -2.52525253, -2.32323232, -2.12121212,
-1.91919192, -1.71717172, -1.51515152, -1.31313131,
-1.11111111, -0.90909091, -0.70707071, -0.50505051,
-0.3030303 , -0.1010101 , 0.1010101 , 0.3030303 ,
0.50505051, 0.70707071, 0.90909091, 1.11111111,
1.31313131, 1.51515152, 1.71717172, 1.91919192,
2.12121212, 2.32323232, 2.52525253, 2.72727273,
2.92929293, 3.13131313, 3.33333333, 3.53535354,
3.73737374, 3.93939394, 4.14141414, 4.34343434,
4.54545455, 4.74747475, 4.94949495, 5.15151515,
5.35353535, 5.55555556, 5.75757576, 5.95959596,
6.16161616, 6.36363636, 6.56565657, 6.76767677,
6.96969697, 7.17171717, 7.37373737, 7.57575758,
7.77777778, 7.97979798, 8.18181818, 8.38383838,
8.58585859, 8.78787879, 8.98989899, 9.19191919,
9.39393939, 9.5959596 , 9.7979798 , 10. ])
==val] x[y
array([-2.12121212])
val
-2.3745682396702437
<25] y[x
array([ 1.69351335, 1.47131924, 1.22371576, 0.9587681 , 0.684928 ,
0.41069988, 0.14430802, -0.10662173, -0.33535303, -0.53629097,
-0.70518496, -0.83927443, -0.93737161, -0.99987837, -1.02873658,
-1.02731441, -1.00023337, -0.9531436 , -0.89245674, -0.82504765,
-0.7579375 , -0.69797133, -0.65150368, -0.62410537, -0.62030365,
-0.64336659, -0.69514097, -0.77595027, -0.88455735, -1.01819364,
-1.17265367, -1.34245142, -1.5210323 , -1.7010322 , -1.8745732 ,
-2.033584 , -2.17013196, -2.2767534 , -2.34676854, -2.37456824,
-2.35586079, -2.28786853, -2.16946611, -2.00125462, -1.7855683 ,
-1.52641324, -1.22934038, -0.90125763, -0.55018832, -0.18498567,
0.18498567, 0.55018832, 0.90125763, 1.22934038, 1.52641324,
1.7855683 , 2.00125462, 2.16946611, 2.28786853, 2.35586079,
2.37456824, 2.34676854, 2.2767534 , 2.17013196, 2.033584 ,
1.8745732 , 1.7010322 , 1.5210323 , 1.34245142, 1.17265367,
1.01819364, 0.88455735, 0.77595027, 0.69514097, 0.64336659,
0.62030365, 0.62410537, 0.65150368, 0.69797133, 0.7579375 ,
0.82504765, 0.89245674, 0.9531436 , 1.00023337, 1.02731441,
1.02873658, 0.99987837, 0.93737161, 0.83927443, 0.70518496,
0.53629097, 0.33535303, 0.10662173, -0.14430802, -0.41069988,
-0.684928 , -0.9587681 , -1.22371576, -1.47131924, -1.69351335])
1.4]) func([
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-69-a7647ebf0a8e> in <module> ----> 1 func([1.4]) <ipython-input-66-27f8a49456fd> in func(x) 1 def func(x): ----> 2 return np.sin(x) + np.sin(x/2) + np.sin(x/3) TypeError: unsupported operand type(s) for /: 'list' and 'int'