Skip to content

Instantly share code, notes, and snippets.

km = KMeans(n_clusters = 5)
y_predicted = km.fit_predict(salary_story[['Total Salary Paid', 'Home Price']])
salary_story['Cluster'] = y_predicted
from sklearn.cluster import KMeans
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import LabelEncoder
sns.set(rc = {'figure.figsize':(14,7)})
sns.scatterplot(data = salary_story, x = 'Total Salary Paid', y = 'Home Price').set(title = "Income per Home Price")
sns.set(rc = {'figure.figsize':(15,8)})
sns.distplot(a=salary_story['Total Salary Paid'], bins = 40, color='green',
hist_kws={"edgecolor": 'black'}).set(title = "Density Plot for Income")
plt.show()
import scipy.stats as stats
plt.figure(figsize=(16, 10))
for f, label in ((same_1990s, "Not Remodelled"),
(remodelled_1990s, "Remodelled"),
(built_1990s, "Built after 1990")):
x = np.sort(price[f])
plt.hist(x, density=True, alpha=0.1)
density = stats.gaussian_kde(x)
price = housing['SalePrice']
tot_liv_area = housing['TotLivArea']
plt.figure(figsize=(9, 6))
plt.scatter(tot_liv_area, price)
plt.ylabel('Sale Price')
plt.xlabel('TotLivArea')
plt.title('Sale Price per Total Living Area')
plt.show()
import seaborn as sns
sns.set(rc = {'figure.figsize':(15,8)})
sns.boxplot(x='OverallQual', y='SalePrice', data=housing).set(title = "House Overall Quality Boxplot")
#Import the following libraries
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import LabelEncoder
import matplotlib.pyplot as plt
#separate numerical and catergorical features
housing_numerical = housing.drop(['PID'], axis =1).select_dtypes(include = ('int64', 'float64'))
@liliya2022
liliya2022 / bar chart
Last active March 10, 2023 01:32
Machine learning blog
def get_feature_groups():
num_features = housing.select_dtypes(include=['int64','float64']).columns
return list(num_features.drop(['PID','SalePrice']))
num_features = get_feature_groups()
corr = housing[['SalePrice'] + num_features].corr()
corr = corr.sort_values('SalePrice', ascending=False)
plt.figure(figsize=(8,10))
sns.barplot(x=corr.SalePrice[1:], y=corr.index[1:], orient='h')
#libraries:
library(shiny)
library(shinythemes)
library(lubridate)
library(dygraphs)
library(xts)
library(tidyverse)
bitcoin <-read.csv(file = 'BTC-USD.csv', stringsAsFactors = F)