Posts

Multiple linear regression for GW depth estimaition

# importing the libraries import matplotlib.pyplot as plt import numpy as np import seaborn as sns import pandas as pd from sklearn import preprocessing # Importing the data set and extracting the dependent and Independent variables data=pd.read_excel( "Amina.xls" ) print (data) x=data.drop( columns =[ 'GWDepth' ]) y=data[ 'GWDepth' ] #Standardisation X=preprocessing.scale(x) Y=preprocessing.scale(y) # Data Visualisation # Building the Correlation Matrix print (sns.heatmap(data.corr())) #plt.show() # Splitting the dataset into training set and test set from sklearn.model_selection import train_test_split X_train , X_test , Y_train , Y_test= train_test_split(X , Y , test_size = 0.2 , random_state = 0 ) # Fitting Multiple Linear Regression to the Training set from sklearn.linear_model import LinearRegression regressor=LinearRegression() regressor.fit(X_train , Y_train) # Predicting the Test set results Y_pred=regressor.predict(X_test) #print(Y_pred) #Calculating...

Interpolation and graph

import numpy as np from scipy import interpolate import matplotlib.pyplot as plt Kc=np.array([ 0.35 , 0.35 , 0.75 , 1.15 , 0.45 ]) Days=np.array([ 1 , 15 , 40 , 90 , 120 ]) f=interpolate.interp1d(Days , Kc) print (f( 20 )) plt.xlabel( 'Days' ) plt.ylabel( 'Kc' ) plt.title( "Kc vs Days" ) plt.plot(Days , Kc , ) plt.show()

Inheritance in Python

  from ntn import chef from chinesechef import chinesechef mychef()=chef() mychef.make_chickpeas() mychinesechef()=chinesechef() mychinesechef.make_tinde() chef.make_chickpeas() class chinesechef: from ntn import chef def make_tinde ( self ): print ( "The chef made tinde" ) class chef: def make_spinach ( self ): print ( "The Chef made spinach" ) def make_chickpeas ( self ): print ( "The Chef made chickpeas" ) def make_special_dish ( self ): print ( "The Chef made paneer" )

To check if a student has a honor's degree (Using Class in python)

  class student: def __init__ ( self , name , gpa , study_field): self .name=name self .gpa=gpa self .study_field=study_field def on_honor_call ( self ): if self .gpa>= 3.5 : return True else : return False then create new file in pycharm from next import student student1=student( "Komal" , 4.2 , "Science" ) student2=student( "Mike" , 3.2 , "Arts" ) print (student2.on_honor_call())

MCQ using Class in Python

  class question: def __init__ ( self , prompt , answer): self .prompt=prompt self .answer=answer then in next sheet from next import question question_prompt = [ "What is the color of apples? \n (a) Red/Green \n (b) Yellow \n (c) White \n\n " , "What is the color of Bananas? \n (a) Red/Green \n (b) Yellow \n (c) White \n\n " , "What is the color of Berry? \n (a) Red/Green \n (b) Yellow \n (c) White \n\n " ] questions = [ question(question_prompt[ 0 ] , "a" ) , question(question_prompt[ 1 ] , "b" ) , question(question_prompt[ 2 ] , "a" ) , ] def run_test (questions): score = 0 for Question in questions: answer = input (question_prompt) if answer == question.answer: score += 1 print ( "You got" + str (score) + "/" + str ( len (Question_prompt) + " correct" )) run_test(questions)

Class in Python

  class student: def __init__ ( self , name , rollno , gpa , is_a_boy): self .name=name self .rollno=rollno self .gpa=gpa self .is_a_boy=is_a_boy Then create new file in pycharm, then type this code from next import student student1=student( "jim" , 24 , 3.2 ,True ) student2=student( "Pam" , 25 , 2.2 ,False ) print (student1.gpa)

calculate power of any number

def raise_to_power(base_num, pow_num): result=1 for index in range(pow_num): result = result * base_num return result print(raise_to_power(2,8))