Posts

Showing posts from July, 2020

logestic regression

Image
import pandas as pd from sklearn import linear_model import matplotlib.pyplot as plt In [59]: df = pd . read_csv ( "areadata.csv" ) df Out[59]: age bought_insaurance 0 22 0 1 25 0 2 47 1 3 52 0 4 46 1 5 56 0 6 24 0 7 65 1 8 23 0 9 32 1 10 43 1 11 34 1 12 45 0 13 54 1 14 65 0 15 13 0 16 42 1 17 35 0 18 53 1 19 61 0 20 62 0 In [60]: % matplotlib inline plt . xlabel ( "age" ) plt . ylabel ( "bought_insaurance" ) plt . scatter ( df . age , df . bought_insaurance , color = "red" , marker = "." ) Out[60]: <matplotlib.collections.PathCollection at 0x18712cad548> In [63]: from sklearn.model_selection import train_test_split x_train , x_test , y_train , y_test = train_test_split ( df [[ "age" ]], df . bought_insaurance , test_size = 0.1 ) In [66]: x_test Out[66]: age 1 25 9 32 4 46 In [67]: x_train Out[67]: age 20 62 12 45 16 42 8 23 18 53 13 54 19 61 7 65 17 35 14 65 2 47 0 22 3 52 6 24 15 13 11 34

linear regression of area and price

Image
import pandas as pd import numpy as np from sklearn import linear_model import matplotlib.pyplot as plt In [31]: df = pd . read_csv ( "areadata.csv" ) df Out[31]: area price 0 2600 550000 1 3000 565000 2 3200 610000 3 3600 680000 4 4000 725000 In [34]: % matplotlib inline plt . xlabel ( "area" ) plt . ylabel ( "price" ) plt . scatter ( df . area , df . price , color = "red" , marker = "+" ) Out[34]: <matplotlib.collections.PathCollection at 0x18712b13c88> In [37]: newdf = df . drop ( "price" , axis = "columns" ) newdf Out[37]: area 0 2600 1 3000 2 3200 3 3600 4 4000 In [39]: model = linear_model . LinearRegression () model . fit ( newdf , df . price ) Out[39]: LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False) In [43]: model . predict ([[ 5000 ]]) Out[43]: array([859554.79452055]) In [44]: model . intercept_ Out[44]: 180616.43835616432

speach recognisation using python

speech recognization. filename = input("please enter audio with extension ")#extension in .wav with sr.AudioFile(filename) as source:     audiofile = recog.listen(source)     try:         text = recog.recognize_google(audiofile)         print(text)     except:         print("check internet connection")     

my first ML project

Image
import matplotlib.pyplot as plt import numpy as np from sklearn import datasets , linear_model from sklearn.metrics import mean_squared_error diabetes = datasets . load_diabetes () #'data', 'target', 'DESCR', 'feature_names', 'data_filename', 'target_filename' diabetes_x = diabetes . data diabetes_x_train = diabetes_x [: - 30 ] diabetes_x_test = diabetes_x [ - 30 :] diabetes_y_train = diabetes . target [: - 30 ] diabetes_y_test = diabetes . target [ - 30 :] model = linear_model . LinearRegression () model . fit ( diabetes_x_train , diabetes_y_train ) diabetes_y_predicted = model . predict ( diabetes_x_test ) print ( "mean_squared_error is" , mean_squared_error ( diabetes_y_test , diabetes_y_predicted )) print ( "weights:" , model . coef_ ) print ( "Interscept:" , model . intercept_ ) #plt.scatter(diabetes_x_test,diabetes_y_test) #plt.show() #plt.plot(dia