Wednesday, March 10, 2021

Support Vector Machine in Python

At first download the Heart Disease Dataset from Kaggle:  https://www.kaggle.com/ronitf/heart-disease-uci.  Following, you should put the dataset in google drive. Then Using Google Colab you can run the following Support Vector Machine code:


!pip install -U -q PyDrive 

from pydrive.auth import GoogleAuth 
from pydrive.drive import GoogleDrive 
from google.colab import auth 
from oauth2client.client import GoogleCredentials 


# Authenticate and create the PyDrive client. 
auth.authenticate_user() 
gauth = GoogleAuth() 
gauth.credentials = GoogleCredentials.get_application_default() 
drive = GoogleDrive(gauth)
link =
'https://drive.google.com/file/d/1OglM8GvGIiVMMUXAchljXc86RtOq9K02
/view?usp=sharing'

import pandas as pd 
import numpy as np
# to get the id part of the file 
id = link.split("/")[-2

downloaded = drive.CreateFile({'id':id}) 
downloaded.GetContentFile('heart.csv'

df = pd.read_csv('heart.csv'
X = df.drop('target', axis=1)
y = df['target']
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y,
 test_size = 0.30)

from sklearn.svm import SVC
svclassifier = SVC(kernel='linear')
svclassifier.fit(X_train, y_train)
y_pred = svclassifier.predict(X_test)
from sklearn.metrics import confusion_matrix, classification_report
print(confusion_matrix(y_test,y_pred))
print(classification_report(y_test,y_pred))
from sklearn import metrics
print("Accuracy:",
metrics.accuracy_score(y_test, y_pred))
print("Precision:",
metrics.precision_score(y_test, y_pred))
print("Recall:",
metrics.recall_score(y_test, y_pred))
print("F1 Score:",metrics.f1_score(y_test, y_pred))

print('Mean Absolute Error:',
 metrics.mean_absolute_error(y_test, y_pred))
print('Mean Squared Error:'
metrics.mean_squared_error(y_test, y_pred))
print('Root Mean Squared Error:'
np.sqrt(metrics.mean_squared_error(y_test, y_pred)))



Output:



Monday, March 8, 2021

Python Custom Module Create

 

Let's say we want to create our own module which have some functions like add, sub, mult, and div.

1st step:

Let's create arithmetic.ipynb file :

Code: 

def add(n1n2):
    return n1 + n2

def sub(n1n2):
    return n1 - n2

def mult(n1n2):
    return n1 * n2

def div(n1n2):
    return n1 / n2

Sample Image:


2nd Step:

Now, download as a .py file ( arithmetic.py) . Then create test.ipynb file:

As Google Colab run in another virtual machine instead of google drive we need to upload the arithmetic.py file in to Colab. So in test.ipynb we will write:


Code:

from google.colab import files
files.upload()


Then , upload the arithmetic.py file. 


3rd Step:  

After uploading, import your custom module arithmetic and call the function add(). Give two input numbers and see the addition result.

Code:

import arithmetic as ar

ar.add(5,6) 

Sample Image:













How to Write Summary of a Research Paper

Paper Summary should contain the following points: What problem author’s solved? What are the motivations for that problem? Why is it import...