Skip to content

Instantly share code, notes, and snippets.

View saimadhu-polamuri's full-sized avatar
💭
For the love of data.

saimadhu saimadhu-polamuri

💭
For the love of data.
View GitHub Profile
from sklearn.impute import SimpleImputer
from sklearn.datasets import load_diabetes
diabetes = load_diabetes()
X, y = diabetes.data, diabetes.target
imp_mode = SimpleImputer(strategy='most_frequent')
X_imputed = imp_mode.fit_transform(X)
from sklearn.impute import SimpleImputer
from sklearn.datasets import load_diabetes
diabetes = load_diabetes()
X, y = diabetes.data, diabetes.target
imp_mean = SimpleImputer(strategy='mean')
X_imputed = imp_mean.fit_transform(X)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, LSTM,Flatten
# Load data
df = pd.read_csv('https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-min-temperatures.csv')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.arima.model import ARIMA
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
# Load the data
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date'])
from statsmodels.tsa.seasonal import seasonal_decompose
# Decompose the time series into its trend, seasonal, and residual components
decomposition = seasonal_decompose(data, model='additive')
# Plot the decomposed time series
fig, ax = plt.subplots()
ax.plot(decomposition.trend, label='Trend')
ax.plot(decomposition.seasonal, label='Seasonal')
ax.plot(decomposition.resid, label='Residual')
from statsmodels.tsa.holtwinters import ExponentialSmoothing
# Define the parameters for the exponential smoothing model
trend = 'additive'
seasonal = 'additive'
# Fit the exponential smoothing model
model = ExponentialSmoothing(data, trend=trend, seasonal=seasonal)
results = model.fit()
from statsmodels.tsa.arima_model import ARIMA
# Define the parameters for the ARIMA model
p = 2
d = 1
q = 1
# Fit the ARIMA model
model = ARIMA(data, order=(p,d,q))
results = model.fit()
import numpy as np
from scipy.stats import ks_2samp
import matplotlib.pyplot as plt
# Generate two random samples
np.random.seed(123)
sample1 = np.random.normal(loc=0, scale=1, size=100)
sample2 = np.random.normal(loc=1, scale=1, size=100)
# Compute the test statistic and p-value
from scipy.stats import kstest
import numpy as np
# Generate a random sample from a normal distribution
sample = np.random.normal(loc=0, scale=1, size=100)
# Perform goodness-of-fit KS test against a normal distribution
statistic, pvalue = kstest(sample, 'norm')
print('Test statistic:', statistic)
print('P-value:', pvalue)
from scipy.stats import ks_2samp
import numpy as np
# Generate two random samples from normal distributions
sample1 = np.random.normal(loc=0, scale=1, size=100)
sample2 = np.random.normal(loc=0.5, scale=1, size=100)
# Perform two-sample KS test
statistic, pvalue = ks_2samp(sample1, sample2)
print('Test statistic:', statistic)