Kaggle competition: Bike Sharing Demand
import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sns
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.losses import categorical_crossentropy
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Activation,BatchNormalization,Conv2D,Dense,Dropout,Flatten,MaxPooling2D
from tensorflow.keras.callbacks import LearningRateScheduler,ModelCheckpoint,EarlyStopping
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, accuracy_score, classification_report<load_from_csv>
train = pd.read_csv('.. /input/train.csv')
 train.head()
train = pd.read_csv('/kaggle/input/Kannada-MNIST/train.csv')
 test = pd.read_csv("/kaggle/input/Kannada-MNIST/test.csv")
 Dig_MNIST = pd.read_csv("/kaggle/input/Kannada-MNIST/Dig-MNIST.csv")
 sample_sub = pd.read_csv("/kaggle/input/Kannada-MNIST/sample_submission.csv" )<prepare_x_and_y>
test = pd.read_csv('.. /input/test.csv')
 test.head()
X=train.iloc[:,1:].values
Y=train.iloc[:,0].values
Y[:10]<train_model>
train.loc[0,'datetime'].split('-')[0]
Y = tf.keras.utils.to_categorical(Y, num_classes=10)
 print(f"Y data shape: {Y.shape}" )<split>
train = pd.read_csv(".. /input/train.csv", parse_dates = ["datetime"])
 test = pd.read_csv(".. /input/test.csv", parse_dates = ["datetime"] )
X_train, X_valid, Y_train, Y_valid = train_test_split(X, Y, test_size = 0.2, random_state=42 )<choose_model_class>
train["year"] = train["datetime"].dt.year
train["hour"] = train["datetime"].dt.hour
train["dayofweek"] = train["datetime"].dt.dayofweek
test["year"] = test["datetime"].dt.year
test["hour"] = test["datetime"].dt.hour
test["dayofweek"] = test["datetime"].dt.dayofweek
train_datagen = ImageDataGenerator(rescale = 1./255,
rotation_range = 10,
width_shift_range = 0.25,
height_shift_range = 0.25,
shear_range = 0.1,
zoom_range = 0.25,
horizontal_flip=False )<define_variables>
y_train = train["count"]
y_train = np.log1p(y_train )
valid_datagen = ImageDataGenerator(rescale=1./255 )<choose_model_class>
train.drop(["datetime", "windspeed", "casual", "registered", "count"], 1, inplace=True)
 test.drop(["datetime", "windspeed"], 1, inplace=True )
model = Sequential([
Conv2D(64, 3, padding='same', input_shape=(28, 28, 1)) ,
BatchNormalization(scale=False, center=True),
Activation('relu'),
Conv2D(64, 3, padding='same'),
BatchNormalization(scale=False, center=True),
Activation('relu'),
MaxPooling2D(2,2),
Dropout(0.2),
Conv2D(128, 3, padding='same'),
BatchNormalization(scale=False, center=True),
Activation('relu'),
Conv2D(128, 3, padding='same'),
BatchNormalization(scale=False, center=True),
Activation('relu'),
MaxPooling2D(2,2),
Dropout(0.2),
Conv2D(256, 3, padding='same'),
BatchNormalization(scale=False, center=True),
Activation('relu'),
Conv2D(256, 3, padding='same'),
BatchNormalization(scale=False, center=True),
Activation('relu'),
MaxPooling2D(2,2),
Dropout(0.2),
Flatten() ,
Dense(256),
BatchNormalization(scale=False, center=True),
Activation('relu'),
Dense(10, activation='softmax')
 ])
 model.summary()<train_model>
rf = RandomForestRegressor(n_estimators=100)
 rf.fit(train,y_train)
 preds = rf.predict(test )
tf.keras.utils.plot_model(model, to_file="model.png", show_shapes=True )<define_variables>
submission = pd.read_csv('.. /input/sampleSubmission.csv')
 submission.head()
learning_rate=0.001
batch_size = 1024
epochs = 50
steps_per_epoch = 100
validation_steps = 50<choose_model_class>
submission["count"] = np.expm1(preds)
 submission.head()
model.compile(optimizer=Adam(lr=learning_rate),
loss=categorical_crossentropy,
metrics=['accuracy'] )<normalization>
submission.to_csv("allrf.csv", index=False )