"""
# I Just wanted to see LeaderBoard In different Way !!!!!!!
"""
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)


df=pd.read_csv("../input/dataset/optiver-realized-volatility-prediction-publicleaderboard.csv")

"""
# Top Twenty on LeaderBoard


"""
df=df.head(20)
df['rank']=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
df['size']=[20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]

import plotly.express as px
fig = px.treemap(df, path=['TeamName'], values='size',hover_data=['rank'],title='Top 20 Teams on LeaderBoard')
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.show()

"""
# Top 10 most Unique Scores on LeaderBoard
"""
df=pd.read_csv("../input/dataset/optiver-realized-volatility-prediction-publicleaderboard.csv")


temp = pd.DataFrame(df.Score.value_counts().reset_index())
temp.columns = ['Common_score','count']
temp=temp.head(10)
               
#df=pd.read_csv("../input/dataset/optiver-realized-volatility-prediction-publicleaderboard.csv")

import matplotlib.pyplot as plt
from palettable.colorbrewer.qualitative import Dark2_6
plt.figure(figsize=(16,10))
my_circle=plt.Circle((0,0), 0.7, color='white')
plt.pie(temp['count'], labels=temp.Common_score, colors=Dark2_6.hex_colors)
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.title('Most Unique Scores on LeaderBoard')
plt.show()
df.iloc[2]

df.drop(2, inplace=True)
import pandas as pd
import numpy as np

import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline

from PIL import Image
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator

import warnings 
warnings.filterwarnings('ignore')
# creating the text variable


def plot_wordcloud(text, mask=None, max_words=400, max_font_size=120, figure_size=(24.0,16.0), 
                   title = None, title_size=40, image_color=False):
    stopwords = set(STOPWORDS)
    more_stopwords = {'one', 'br', 'Po', 'th', 'sayi', 'fo', 'Unknown'}
    stopwords = stopwords.union(more_stopwords)

    wordcloud = WordCloud(background_color='white',
                    stopwords = stopwords,
                    max_words = max_words,
                    max_font_size = max_font_size, 
                    random_state = 42,
                    mask = mask)
    wordcloud.generate(text)
    
    plt.figure(figsize=figure_size)
    if image_color:
        image_colors = ImageColorGenerator(mask);
        plt.imshow(wordcloud.recolor(color_func=image_colors), interpolation="bilinear");
        plt.title(title, fontdict={'size': title_size,  
                                  'verticalalignment': 'bottom'})
    else:
        plt.imshow(wordcloud);
        plt.title(title, fontdict={'size': title_size, 'color': 'green', 
                                  'verticalalignment': 'bottom'})
    plt.axis('off');
    plt.tight_layout()  
"""
# Teams WordCloud
"""

text1 = " ".join(title for title in df.TeamName)

plot_wordcloud(text1, max_words=800, max_font_size=80, figure_size=(14,10))
"""
# I have used copied this code from here!

[link](https://www.kaggle.com/sankalpsrivastava26/catboost-optimization)

"""

import numpy as np # linear algebra
import pandas as pd

train = pd.read_csv("../input/optiver-realized-volatility-prediction/train.csv")
test = pd.read_csv("../input/optiver-realized-volatility-prediction/test.csv")
train
x_train = train.drop(['target'],axis=1)
y_train = train['target']
x_test = test.drop(['row_id'],axis=1)
from catboost import CatBoostRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import optuna
from warnings import filterwarnings
from sklearn.neighbors import KNeighborsRegressor
from sklearn.neural_network import MLPRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor
from lightgbm import LGBMRegressor


filterwarnings("ignore", category=DeprecationWarning) 
filterwarnings("ignore", category=FutureWarning) 
filterwarnings("ignore", category=UserWarning)
X_train,X_val,Y_train,Y_val = train_test_split(x_train,y_train,random_state=26)
def check_rmse(model,x_val,y_val):
    pred = model.predict(x_val)
    return np.sqrt(mean_squared_error(y_val,pred))

knn_reg = KNeighborsRegressor(n_jobs=-1)
xgb_reg = XGBRegressor(n_jobs=-1)
lgbm_reg = LGBMRegressor(n_jobs=-1)
cat_reg =  CatBoostRegressor()

models = [knn_reg,xgb_reg,lgbm_reg,cat_reg]
models_name = ['knn_reg','xgb_reg','lgbm_reg','cat_reg']

rmse_error = []
for i,model in enumerate(models):
    model.fit(X_train,Y_train)
    rmse = check_rmse(model,X_val,Y_val)
    rmse_error.append(rmse)
    print(f"Model : {models_name[i]}   rmse = {rmse}")
    

import matplotlib.pyplot as plt
%matplotlib inline   

plt.barh(models_name,rmse_error)
plt.ylabel("Models")
plt.xlabel("RMSE") 
plt.show()