Posts

Classification using python

  import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier # Load the data df = pd.read_csv( 'data.csv' ) # Split the data into train and test sets X_train, X_test, y_train, y_test = train_test_split(df.drop( 'target' , axis= 1 ), df[ 'target' ], test_size= 0.25 ) # Create the model model = DecisionTreeClassifier() # Fit the model to the training data model.fit(X_train, y_train) # Predict the labels for the test data y_pred = model.predict(X_test) # Evaluate the model accuracy = np.mean(y_pred == y_test) print( 'Accuracy:' , accuracy)

Logistic Regression in Python

 import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression # Load the data df = pd.read_csv('data.csv') # Split the data into train and test sets X_train, X_test, y_train, y_test = train_test_split(df.drop('target', axis=1), df['target'], test_size=0.25) # Create the model model = LogisticRegression() # Fit the model to the training data model.fit(X_train, y_train) # Predict the labels for the test data y_pred = model.predict(X_test) # Evaluate the model accuracy = np.mean(y_pred == y_test) print('Accuracy:', accuracy)

Classification code in python

https://www.kaggle.com/embed/drnitinmishra/classification-using-one-hot-encoding-exp-6?kernelSessionId=62599262

Function to Solve Null Value Problem-Filling Null Values

We wanted to create a function, which can fill missing values automatically. Our aim is to create a function that can take the data frame as input, finds the missing values, and fills the missing values with appropriate values.  So we have created our function, which will find out, numerical and categorical values from the data frame, then it will also find out which numerical and categorical values are missing.  It will fill those numerical and categorical values with different methods, numerical values will be filled with mean and categorical values will be filled with the most frequently occurring category. To Use this Function just pass pandas DataFrame to the function and it will do the rest. Suppose the data frame is d d=clean_missing(d) def clean_missing(df):     from sklearn.pipeline import Pipeline     from sklearn.impute import SimpleImputer     from sklearn.compose import ColumnTransformer     df_missing_values = df.isnull().s...

BASIC PANDAS FOR DATA ANALYSIS AND MACHINE LEARNING

Image
                         BASIC PANDAS FOR DATA ANALYSIS AND MACHINE LEARNING READING AND WRITING THE DATA df=pd.read_csv("/kaggle/input/heart.csv") df.to_csv("heart.csv") df.to_excel("heart.xls") xlsx = pd.ExcelFile("/kaggle/working/heart.xls")   Any data frame can be saved as a file. And any file can be read back to the data frame and vice versa. SELECTING DATA FROM DATA FRAME df.loc[1:10,["sex","chol","target"]] df[(df.target==1) | (df.sex==1)] df[(df.target==1) & (df.sex==1)] COUNTING 

Online Python Programming platforms

  No one wants to waste time in installation and package integration. So I am suggesting some online platforms where you can just log in and start programming. Google Colab https://www.kaggle.com Some Amazon products you can try Slippers Paragon chappals https://amzn.to/2MnhFE3

Fake news

https://www.summer.harvard.edu/inside-summer/4-tips-spotting-fake-news-story