Skip to content

Instantly share code, notes, and snippets.

View mahimairaja's full-sized avatar
:electron:
One PR at a Time

Mahimai Raja J mahimairaja

:electron:
One PR at a Time
View GitHub Profile
import torch
x = torch.ones(3) # Input Tensor
y = torch.zeros(2) # Expected Output Tensor
w = torch.randn(3, 2, requires_grad=True) # Weight matrix
b = torch.randn(2 , requires_grad=True) # Bias
z = torch.matmul(x, w) + b # Calculated output
@mahimairaja
mahimairaja / json-to-excel.py
Created June 8, 2023 12:11
To write a excel using the data from json.
import pandas as pd
import json
def readJson(filename,) -> dict:
"""
Reads a json file and returns a dictionary
"""
file = open(filename, 'r')
data = file.read()
file.close()
from super_gradients.training import models
import supervision as sv
import torch
import cv2
# install the required packages
# pip install -q super-gradients==3.1.1 supervision
# predict function to predict the image
def predict(img, model):
# pip install rembg
from PIL import Image
from rembg import remove
input = Image.open('mahimai.jpeg')
output = remove(input)
output.save('output.png')
@mahimairaja
mahimairaja / std-vs-normal-distribution.py
Created February 11, 2023 13:04
To analyse the data points based on normal distribution and standard deviation.
from scipy import stats
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('your_csv_name')
col = df['Grade']
density = stats.gaussian_kde(col)
col.plot.density()
@mahimairaja
mahimairaja / multiClassLogisticPipeLine.py
Created January 24, 2023 00:16
Logistic Regression Pipeline to solve multi-class Classification problem.
# Author : Mahimai Raja J
# Date : 24.01.2023
from sklearn.preprocessing import StandardScaler
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
# Define preprocessing for numeric columns (scale them)
feature_columns = [0,1,2,3]
@mahimairaja
mahimairaja / regressionPipeline.py
Created January 23, 2023 00:56
Training a Linear Regression model in Pipeline.
# Train the model
import numpy as np
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.linear_model import LinearRegression
# Define preprocessing for numeric columns (scale them)