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
| import matplotlib.pyplot as plt | |
| from numpy.random import normal, uniform | |
| import pandas as pd | |
| import os | |
| os.listdir() | |
| data = pd.read_csv("DSI.csv") | |
| data.head() |
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
| scores = cross_val_score(LinearRegression(), Xr, yr, cv=397, scoring = "r2") | |
| print("Cross-validated scores:", scores) | |
| print("Average: ", scores.mean()) | |
| print("Variance: ", np.std(scores)) |
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
| loo = LeaveOneOut() | |
| ytests = [] | |
| ypreds = [] | |
| for train_idx, test_idx in loo.split(Xr): | |
| X_train, X_test = X_array[train_idx], X_array[test_idx] #requires arrays | |
| y_train, y_test = y_array[train_idx], y_array[test_idx] | |
| model = LinearRegression() | |
| model.fit(X = X_train, y = y_train) | |
| y_pred = model.predict(X_test) |
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
| mapping_dict ={} | |
| for i, img_url in enumerate(image_list[0:10000]): | |
| img_name = "img_%05d" % (i,) | |
| mapping_dict[img_name] = img_url | |
| if (img_url == np.nan) | (str(img_url) == "nan"): | |
| continue | |
| else: | |
| # Uses the creds in ~/.aws/credentials | |
| s3_image_filename = img_name |
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
| # http://docs.aws.amazon.com/rekognition/latest/dg/get-started-exercise.html | |
| fileName='img_00001' | |
| bucket='bucket_name' | |
| client=boto3.client('rekognition') | |
| ## ^^ we only need to do this code once for the following examples. I include it | |
| ## re-instated in case you want to check out different pics. | |
| response = client.detect_labels(Image={'S3Object':{'Bucket':bucket,'Name':fileName}},MinConfidence=75) | |
| response |
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
| fileName= 'img_00006' | |
| bucket='bucket_name' | |
| text_in_image = client.detect_text(Image={'S3Object':{'Bucket':bucket,'Name':fileName}}) | |
| text_in_image["TextDetections"] |
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
| fileName= 'img_00012' | |
| bucket='bucket_name' | |
| celeb_detect = client.recognize_celebrities(Image={'S3Object':{'Bucket':bucket,'Name':fileName}}) | |
| celeb_detect["CelebrityFaces"] |
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
| bucket_name = 'bucket_name' | |
| s3 = boto3.resource('s3') | |
| bucket = s3.Bucket(bucket_name) | |
| images = [img.key for img in bucket.objects.all()] #fetches image names from your S3 bucket | |
| client = boto3.client('rekognition') | |
| results_wide = [] | |
| results_long = [] | |
| for img in images: |
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
| model_data['activity'] = model_data['Activity'].map({'Scuba Diving':'Diving', 'Scuba diving':'Diving','2 boats capsized': 'Disaster','Treading water': 'Swimming', | |
| 'Air Disaster': 'Disaster','Surfing': 'Surfing', 'Night bathing': 'Swimming', 'Snorkeling': 'Swimming','Measuring sharks': 'Handling', | |
| 'Swimming': 'Swimming', 'Surfing': 'Surfing', 'Kayaking / Fishing': 'Fishing','Body surfing': 'Surfing', 'Fishing': 'Fishing', | |
| 'Spearfishing': 'Spear Fishing','Swimming, poaching abalone': 'Diving', 'Wading': 'Shallow Water', 'Canoeing': 'Rowing', | |
| 'Feeding sharks': 'Handling', 'Paddle boarding':'Rowing','SUP':'Rowing','Body boarding':'Surfing', 'Touching a shark': 'Handling', | |
| 'Attempting to lasso a shark':'Handling','Surfing ':'Surfing','Tagging sharks':'Handling', 'Kakaying': 'Rowing','Washing hands':'Fishing', | |
| 'Grabbing shark for a selfie': 'Handling', 'Kayak fishin |
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
| import os | |
| import pandas as pd | |
| from time import sleep | |
| from selenium import webdriver | |
| from selenium.webdriver.common.by import By | |
| from selenium.webdriver.support.ui import WebDriverWait | |
| from selenium.webdriver.support import expected_conditions as EC | |
| from selenium.webdriver.firefox.firefox_binary import FirefoxBinary |
OlderNewer