This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Rotating an image | |
| rotated0 = imutils.rotate_bound(rgb_img,0) | |
| rotated45 = imutils.rotate_bound(rgb_img,45) | |
| rotated90 = imutils.rotate_bound(rgb_img,90) | |
| fig,axs = plt.subplots(1,3, figsize=(30,15)) | |
| axs[0].imshow(rotated0) | |
| axs[1].imshow(rotated45) | |
| axs[2].imshow(rotated90) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Convert image to RGB from BGR | |
| rgb_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB) | |
| plt.figure(figsize=figsize) | |
| plt.imshow(rgb_img) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Render image from URL | |
| req = urllib.request.urlopen('https://www.sportbible.com/cdn-cgi/image/width=648,quality=70,format=webp,fit=pad,dpr=1/https%3A%2F%2Fs3-images.sportbible.com%2Fs3%2Fcontent%2Fcf2701795dd2a49b4d404d9fa38f99fd.jpg') | |
| arr = np.asarray(bytearray(req.read()), dtype=np.uint8) | |
| bgr_img = cv2.imdecode(arr, -1) # 'Load it as it is' | |
| # Determine the figures size in inches to fit image | |
| dpi = plt.rcParams['figure.dpi'] | |
| height, width, depth = bgr_img.shape | |
| figsize = width / float(dpi), height / float(dpi) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_thermo_info(material): | |
| '''Carries out query from NIST Chemistry WebBook for thermodynamic properties of a chemical compound | |
| Args: | |
| material (str): Name of compound to get thermodynamic info for | |
| Returns: | |
| Pandas dataframe containing query results | |
| Raises: | |
| If table is not found, then dataframe is filled with NaNs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Replace commas with %2C for proper querying (this is the HEX code to represent a comma) | |
| mat_corr = material.replace(",", "%2C").replace("(", "%28").replace(")", "%29").replace("+", "%2B") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| contigency= pd.crosstab(vid_df_copy['sentiment'],vid_df_copy['Live or Studio']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| emotions = ['joy', 'positive', 'anticipation', 'sadness','surprise', 'negative', 'anger', 'disgust', 'trust','fear'] | |
| for emotion in emotions: | |
| vid_df_copy[emotion] = [0 if emotion not in NRCLex(x).raw_emotion_scores else NRCLex(x).raw_emotion_scores[emotion] for x in vid_df_copy['denoised_str']] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vid_df_copy['joy'] = [0 if 'joy' not in NRCLex(x).raw_emotion_scores else NRCLex(x).raw_emotion_scores['joy'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy['positive'] = [0 if 'positive' not in NRCLex(x).raw_emotion_scores else NRCLex(x).raw_emotion_scores['positive'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy['anticipation'] = [0 if 'anticipation' not in NRCLex(x).raw_emotion_scores else NRCLex(x).raw_emotion_scores['anticipation'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy['sadness'] = [0 if 'sadness' not in NRCLex(x).raw_emotion_scores else NRCLex(x).raw_emotion_scores['sadness'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy['surprise'] = [0 if 'surprise' not in NRCLex(x).raw_emotion_scores else NRCLex(x).raw_emotion_scores['surprise'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy['negative'] = [0 if 'negative' not in NRCLex(x).raw_emotion_scores else NRCLex(x).raw_emotion_scores['negative'] for x in vid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sid = SentimentIntensityAnalyzer() | |
| vid_df_copy['compound'] = [sid.polarity_scores(x)['compound'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy['neg'] = [sid.polarity_scores(x)['neg'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy['neu'] = [sid.polarity_scores(x)['neu'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy['pos'] = [sid.polarity_scores(x)['pos'] for x in vid_df_copy['denoised_str']] | |
| vid_df_copy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| classifier = NaiveBayesClassifier.train(train_data) | |
| print("Gaussian Naive Bayes accuracy is:", classify.accuracy(classifier, test_data)) | |
| print(classifier.show_most_informative_features(10)) |