Skip to content

Instantly share code, notes, and snippets.

View sparshs413's full-sized avatar
🏠
Working from home

Sparsh Sihotiya sparshs413

🏠
Working from home
View GitHub Profile
@sparshs413
sparshs413 / Codes.cpp
Last active January 17, 2021 02:40
Contains the Code snippets for Session on C++
// Cout
// #include <iostream>
// using namespace std;
// int main()
// {
// char sample[] = "Electronics Club";
// cout << sample << " , IIT Kanpur";
// return 0;
# Let’s start with importing libraries:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt #data visualization
from sklearn.datasets import make_blobs #synthetic dataset
from sklearn.neighbors import KNeighborsClassifier #kNN classifier
from sklearn.model_selection import train_test_split #train and test sets
#Non-Linear SVM Example
#For this example, we'll use a slightly more complicated dataset to show one of the areas SVMs shine in. Let's import some packages.
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets
from sklearn import svm
#This set of imports is similar to those in the linear example, except it imports one more thing. Now we can use a dataset directly from the Scikit-learn library.
# non-linear data
# We'll start by importing a few libraries that will make it easy to work with most machine learning projects.
import matplotlib.pyplot as plt
import numpy as np
from sklearn import svm
# For a simple linear example, we'll just make some dummy data and that will act in the place of importing a dataset.
# linear data
X = np.array([1, 5, 1.5, 8, 1, 9, 7, 8.7, 2.3, 5.5, 7.7, 6.1])
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#Loading dataset – User_Data
dataset = pd.read_csv('...\\User_Data.csv')
#Now, to predict whether a user will purchase the product or not, one needs to find out the relationship between Age and Estimated Salary. Here User ID and Gender are not important factors for finding out this.
# input
x = dataset.iloc[:, [2, 3]].values
# imports
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
# generate random data-set
np.random.seed(0)
x = np.random.rand(100, 1)
y = 2 + 3 * x + np.random.rand(100, 1)
# imports
import numpy as np
class LinearRegressionUsingGD:
"""Linear Regression Using Gradient Descent.
Parameters
----------
eta : float
Learning rate