Posts

Showing posts from 2025

The Other Roshan

In a small town nestled between the hills of Kerala, there lived a young man named Kichu . His full name was Krishna Kumar , but ever since his childhood friends watched a movie called Kattappanayile Hrithik Roshan , they teased him with the nickname Kattappanayile Roshan . Kichu didn’t mind. He wasn’t a star, nor did he want to be. He worked at a local printing press, earned just enough to help his mother, and cracked jokes that made even the grumpiest neighbor laugh. One day, a marriage proposal came to Kichu’s house. The girl, Anu, was beautiful, ambitious, and had always dreamt of marrying someone tall, rich, and charming her version of Hrithik Roshan . But her parents pressured her into accepting Kichu, saying, “Looks fade, but good men stay.” She reluctantly agreed. The wedding happened, but things were never warm between them. Anu kept comparing Kichu to the men she had once dreamed of the "city boys" with high paying jobs and foreign degrees. She often muttered, ...

Random Forest - Python Code

 import pandas as pd from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score,classification_report data = {     'CGPA': ['>=9', '<9', '>=9', '<9', '>=9'],     'Interactivity': ['Yes', 'No', 'No', 'No', 'Yes'],     'Comm': ['Good', 'Moderate', 'Moderate', 'Moderate', 'Moderate'],     'Practical': ['Good', 'Good', 'Average', 'Average', 'Average'],     'JobOffer': ['Yes', 'No', 'Yes', 'No', 'Yes'] } df=pd.DataFrame(data) df.replace({'>=9':1,'<9':0,'Yes':1,'No':0,'Good':1,'Moderate':0,'Average':0},inplace=True) X=df.drop('JobOffer',axis=1) y=df['JobOffer'] X_train,X_test,y...

ID3 - Python Code

 import pandas as pd import matplotlib.pyplot as plt from sklearn import tree from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score data = {     'Outlook': ['Sunny', 'Sunny', 'Overcast', 'Rain', 'Rain', 'Rain', 'Overcast',                 'Sunny', 'Sunny', 'Rain', 'Sunny', 'Overcast', 'Overcast', 'Rain'],     'Temperature': ['Hot', 'Hot', 'Hot', 'Mild', 'Cool', 'Cool', 'Cool',                     'Mild', 'Cool', 'Mild', 'Mild', 'Mild', 'Hot', 'Mild'],     'Humidity': ['High', 'High', 'High', 'High', 'Normal', 'Normal', 'Normal',                  'High', 'Normal', 'Normal', ...

Perceptron for AND Gate - Python Code

 import numpy as np def step(x):     return 1 if x>=0 else 0 def train(X,y):     w=np.zeros(X.shape[1])     b=0     for _ in range(5):         print(f'Epoch : {_}')         for i in range(len(X)):             z=np.dot(X[i],w)+b             y_pred=step(z)             error=y[i]-y_pred             w+=error*X[i]             b+=error         print(f'Weights : {w}, Bias : {b}')     return w,b def predict(X,w,b):     return [step(np.dot(x,w)+b) for x in X]  X=np.array([[0,0], [0,1], [1,0], [1,1]]) y=np.array([0,0,0,1]) w,b=train(X,y) print("Prediction:", predict(X,w,b))

Multiple Linear Regression - Python Code

import numpy as np import matplotlib.pyplot as plt X=np.array([[1,4],[2,5],[3,8],[4,2]]) Y=np.array([1,6,8,12]) X_bias=np.hstack((np.ones((X.shape[0],1)),X)) beta=np.linalg.inv(X_bias.T.dot(X_bias)).dot(X_bias.T).dot(Y) Y_pred=X_bias.dot(beta) print("Predicted values:",Y_pred) plt.scatter(Y,Y_pred,color='blue',label='Predicted vs Actual') #plt.plot(Y,Y,color='red',linestyle='--',label='Ideal Fit') plt.plot(Y,Y,'r--',label='Ideal Fit') plt.xlabel('Actual X') plt.ylabel('Actual Y') plt.title('Multiple Linear Regression') plt.legend() plt.grid(True) plt.show()

Simple Linear Regression - Python Code

 import numpy as np import matplotlib.pyplot as plt x=np.array([1,2,3,4,5]) y=np.array([1.2,1.8,2.6,3.2,3.8]) xmean=np.mean(x) ymean=np.mean(y) nr=np.sum((x-xmean)*(y-ymean)) dr=np.sum((x-xmean) ** 2) b1=nr/dr b0=ymean-b1*xmean print(f"Estimated coefficients : b0={b0},b1={b1}") ypred_line=b0+b1*x print(f"y_predicted_line : {ypred_line}") print('Prediction for x=7') x_new=7 ypred_new=b0+b1*x_new print(f"Prediction for x :{x_new}, y:{ypred_new}") plt.scatter(x,y,color='blue',label='Original Data') plt.plot(x,ypred_line,color='red',label='Regression Line') plt.xlabel('x') plt.ylabel('y') plt.title('Simple Linear Regression') plt.legend() plt.grid(True) plt.show()