Kaggle competition: Предсказание положения космических объектов
ids=test['PassengerId']
predictions = clf_best.predict(X_test)
 my_submission = pd.DataFrame({ 'PassengerId' : ids, 'Survived': predictions })
 my_submission.to_csv('submission.csv', index=False)
<load_from_csv>
warnings.filterwarnings('ignore')
train = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/train.csv')
 test = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/test.csv')
 frame =(train, test)
 df1 = pd.concat(frame, keys = ['train','test'] )<sort_values>
initi = pd.read_csv('/kaggle/input/sputnik/train.csv' )
df1.corr().sum().sort_values(ascending=False )<sort_values>
lag_period = 24
resultsx = pd.DataFrame()
for j in range(600):
dfr = initi[initi.sat_id==j][['x','type']]
train = dfr[dfr.type=='train'].reset_index(drop=True)
 test = dfr[dfr.type=='test'].reset_index(drop=True)
 i=0
while(i*24<len(test)) :
df = pd.concat(( train, test), axis = 0, ignore_index=True)
 df['target'] = df.x
features = []
for period_mult in range(1,3,1):
df["lag_period_{}".format(period_mult)] = df.target.shift(period_mult*lag_period)
 features.append("lag_period_{}".format(period_mult))
df['lagf_mean'] = df[features].mean(axis = 1)
 features.extend(['lagf_mean'])
 model = LinearRegression()
train_df = df[df.type=='train'][features + ['target']].dropna()
test_df = df[df.type=='test'][features].reset_index(drop=True)
 test_df = test_df.loc[:23,:]
model.fit(train_df.drop(['target'], axis = 1), train_df['target'])
 forecast = model.predict(test_df)
 test.loc[i*24:i*24+23,:]['x'] = forecast
test.loc[i*24:i*24+23,:]['type'] = 'train'
i+=1
resultsx = pd.concat(( resultsx, test),axis=0, ignore_index=True )
df2 = df1.sort_values(by = 'GrLivArea')
 df3 = df2.isnull().sum().sort_values(ascending= False)
 df3 = df2.isnull().sum().sort_values(ascending= False)
 df3.head(40)
<data_type_conversions>
resultsx.drop(['type'], axis=1, inplace=True )
for column in ['LotFrontage', 'GarageQual', 'GarageYrBlt', 'GarageFinish',
'GarageCond', 'GarageType', 'BsmtExposure', 'BsmtCond', 'BsmtQual',
'BsmtFinType2', 'BsmtFinType1', 'MasVnrType', 'MasVnrArea', 'MSZoning',
'Utilities', 'Functional', 'BsmtFullBath', 'BsmtHalfBath', 'GarageArea',
'BsmtFinSF2', 'Exterior1st', 'TotalBsmtSF', 'GarageCars', 'BsmtUnfSF',
'Electrical','BsmtFinSF1','KitchenQual','SaleType','Exterior2nd']:
df2[column].fillna(method='ffill',inplace=True )<drop_column>
lag_period = 24
resultsy= pd.DataFrame()
for j in range(600):
dfr = initi[initi.sat_id==j][['y','type']]
train = dfr[dfr.type=='train'].reset_index(drop=True)
 test = dfr[dfr.type=='test'].reset_index(drop=True)
 i=0
while(i*24<len(test)) :
df = pd.concat(( train, test), axis = 0, ignore_index=True)
 df['target'] = df.y
features = []
for period_mult in range(1,3,1):
df["lag_period_{}".format(period_mult)] = df.target.shift(period_mult*lag_period)
 features.append("lag_period_{}".format(period_mult))
df['lagf_mean'] = df[features].mean(axis = 1)
 features.extend(['lagf_mean'])
 model = LinearRegression()
train_df = df[df.type=='train'][features + ['target']].dropna()
test_df = df[df.type=='test'][features].reset_index(drop=True)
 test_df = test_df.loc[:23,:]
model.fit(train_df.drop(['target'], axis = 1), train_df['target'])
 forecast = model.predict(test_df)
 test.loc[i*24:i*24+23,:]['y'] = forecast
test.loc[i*24:i*24+23,:]['type'] = 'train'
i+=1
resultsy = pd.concat(( resultsy, test),axis=0, ignore_index=True )
df3.index[0:6]
df2.drop(['PoolQC', 'MiscFeature', 'Alley', 'Fence', 'FireplaceQu'],axis=1, inplace=True )<sort_values>
resultsy.drop(['type'], axis=1, inplace=True )
columns1 = ['LotFrontage','LotArea','TotalBsmtSF','MasVnrArea']
df2[columns1].sort_values(by = columns1,ascending=False)[0:4]
df2.drop(df2[df2['Id'] == 1298].index, inplace = True)
 df2.drop(df2[df2['Id'] == 386].index, inplace = True)
 df2.drop(df2[df2['Id'] == 934].index, inplace = True)
 df2.drop(df2[df2['Id'] == 313].index, inplace = True)
<categorify>
resultsz.drop(['type'], axis=1, inplace=True )
df2_dummy = pd.get_dummies(df2 )<define_variables>
all_results = pd.concat(( resultsx,resultsy,resultsz), axis=1 )
Id = df2_dummy.loc['test']
dftest = df2_dummy.loc['test']
dftrain = df2_dummy.loc['train']
Id = Id.Id<drop_column>
df = pd.concat(( all_results, initi[initi.type=='test'][['x_sim', 'y_sim', 'z_sim']].reset_index(drop=True)) , axis=1 )
dftrain.dropna(axis = 0, inplace = True)
 dftest.drop(['SalePrice','Id'], axis =1, inplace=True )<prepare_x_and_y>
df.loc[:243,:]
dftrain_X = dftrain.drop(['SalePrice','Id'], axis = 1)
 dftrain_y = dftrain['SalePrice']<train_model>
df['error'] = np.linalg.norm(df[['x', 'y', 'z']].values - df[['x_sim', 'y_sim', 'z_sim']].values, axis=1 )
xgboost = xgboost.XGBRegressor(learning_rate=0.05,
colsample_bytree = 0.5,
subsample = 0.8,
n_estimators=1000,
max_depth=5,
gamma=5)
 xgboost.fit(dftrain_X, dftrain_y)
<save_to_csv>
submit = df[['error']]
predictions= xgboost.predict(dftest)
 solution = pd.DataFrame({"Id": Id, 'SalePrice': predictions})
 solution.to_csv('house_pred.csv', index=False )<import_modules>
sub = pd.read_csv('/kaggle/input/sputnik/sub.csv' )
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC, LinearSVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB<load_from_csv>
submit['id'] =(sub.reset_index() ).id
titanic_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/test.csv")
 titanic_df.head()<load_from_csv>
submit.index=sub.id
def get_combined_data() :
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 targets = train.Survived
train.drop('Survived', 1, inplace=True)
 combined = train.append(test)
 combined.reset_index(inplace=True)
 combined.drop('index', inplace=True, axis=1)
 return combined<feature_engineering>
submit.drop(['id'], axis=1, inplace=True )
combined['Cabin'][combined.Cabin.isnull() ] = 'U0'<feature_engineering>
submit.to_csv('submit1.csv' )