import numpy as np import pandas as pd import seaborn as sns import statsmodels.formula.api as sm import statsmodels.imputation.mice as mice from statsmodels.regression.linear_model import OLS from collections import defaultdict import matplotlib.pyplot as plt from sklearn.feature_selection import VarianceThreshold from sklearn.preprocessing import PolynomialFeatures from sklearn.feature_selection import SelectKBest from sklearn.feature_selection import chi2 #myds = pd.read_csv('catalog_result.csv') myds = pd.read_csv('catalog_result_socials.csv', encoding = "ISO-8859-1") genres = pd.get_dummies(myds['RELEASE_GENRE']) LABEL_COUNTRY = pd.get_dummies(myds['LABEL_COUNTRY']) df = pd.DataFrame({ "total_rev": myds['TOTAL_GROSS_REVENUE'], "rev_recip": np.reciprocal(myds['TOTAL_GROSS_REVENUE']), "rev_log": np.log(myds['TOTAL_GROSS_REVENUE']), #"total_physical_rev": myds['PHYSICAL_GROSS_REVENUE'], #"num_cds": myds['NUM_OF_CDS'], "num_active_releases": myds['NUM_ACTIVE_RELEASES'], #"cd_revenue": myds['CD_REVENUE_UNITS_SOLD'], "spotify_passive_streams": myds['SPOTIFY_STREAMS_PASSIVE_DISC_TOTAL'], "spotify_playlist_streams": myds['SPOTIFY_PLAYLISTS_STREAMS_TOTAL'], "spotify_active_streams": myds['SPOTIFY_STREAMS_ACTIVE_DISC_TOTAL'], "spotify_collection_streams": myds['SPOTIFY_STREAMS_COLLECTION_TOTAL'], "spotify_total_streams": myds['SPOTIFY_OVERALL_STREAMS_TOTAL'], "apple_passive_streams": myds['APPLE_STREAMS_PASSIVE_DISC_TOTAL'], "apple_active_streams": myds['APPLE_STREAMS_ACTIVE_DISC_TOTAL'], "apple_collection_streams": myds['APPLE_STREAMS_COLLECTION_TOTAL'], "apple_total_streams": myds['APPLE_OVERALL_STREAMS_TOTAL'], "amazon_total_streams": myds['AMAZON_OVERALL_STREAMS_TOTAL'], "pandora_total_streams": myds['PANDORA_OVERALL_STREAMS_TOTAL'], "youtube_audio_streams": myds['YOUTUBE_AUDIO_OVERALL_STREAMS_TOTAL'], "shazam_total_streams": myds['SHAZAM_OVERALL_STREAMS_TOTAL'], "alexa_total_streams": myds['ALEXA_OVERALL_STREAMS_TOTAL'], "itunes_total_downloads": myds['ITUNES_TOTAL_DOWNLOADS'], "amazon_total_downloads": myds['AMAZON_TOTAL_DOWNLOADS'], "google_total_downloads": myds['GOOGLE_PLAY_DOWNLOADS_TOTAL'], #social features: "fb_likes": myds['fb_likes'], "twitter_followers": myds['twitter_followers'], "youtube_subs": myds['youtube_subs'], "wiki_pageviews": myds['wiki_pageviews'], "insta_followers": myds['insta_followers'], }) #impute NaN with 0s #df = df.fillna(0) av = pd.concat([df, genres, LABEL_COUNTRY] , axis=1) av1 = pd.concat([av, LABEL_COUNTRY] , axis=1) corr2 = df.corr() print(corr2) sns.heatmap(corr2) #plots plot1 = av1.plot(y="total_rev",x="apple_total_streams",kind='scatter') #plot1.set_ylim(0,200000) #plot1.set_xlim(0,500000) plot2 = av1.plot(y="total_rev",x="alexa_total_streams",kind='scatter') plot2.set_ylim(0,300000) plot2.set_xlim(0,100000) plot3 = av1.hist("total_rev", bins=100) plot4 = av1.hist("rev_log", bins=100) plot5 = av1.hist("rev_recip", bins=100) plot6 = av1.plot(y="total_rev",x="spotify_playlist_streams",kind='scatter') # print("Plot 1:") # print(plot1) #plot2, plot3, plot4, plot5, plot6) #print plt.hist(np.reciprocal(myds['TOTAL_GROSS_REVENUE']), bins=100) #print plt.hist(myds['TOTAL_GROSS_REVENUE'], bins=100,range=(10000,1000000)) fml = "total_rev ~ num_active_releases + spotify_playlist_streams + spotify_active_streams + spotify_passive_streams + spotify_collection_streams + spotify_total_streams + apple_active_streams + apple_passive_streams + apple_collection_streams + apple_total_streams + amazon_total_streams + pandora_total_streams + shazam_total_streams + alexa_total_streams + youtube_audio_streams + itunes_total_downloads + amazon_total_downloads + google_total_downloads + fb_likes + twitter_followers + youtube_subs + wiki_pageviews + insta_followers" #fml = "rev_recip ~ total_physical_rev + num_cds + num_active_releases + cd_revenue + spotify_playlist_streams + spotify_active_streams + spotify_collection_streams + spotify_total_streams + apple_active_streams + apple_collection_streams + apple_total_streams + amazon_total_streams + pandora_total_streams + shazam_total_streams + alexa_total_streams + youtube_audio_streams + itunes_total_downloads + amazon_total_downloads + google_total_downloads" #fml = "rev_log ~ total_physical_rev + num_cds + num_active_releases + cd_revenue + spotify_playlist_streams + spotify_active_streams + spotify_passive_streams + spotify_collection_streams + spotify_total_streams + apple_active_streams + apple_passive_streams + apple_collection_streams + apple_total_streams + amazon_total_streams + pandora_total_streams + shazam_total_streams + alexa_total_streams + youtube_audio_streams + itunes_total_downloads + amazon_total_downloads + google_total_downloads" result = sm.ols(fml, data=av1).fit() print(result.summary()) plt.show()