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
| val intent = Intent(Intent.ACTION_SEND) | |
| val activityList = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL) | |
| when { | |
| activityList.size > 1 -> { | |
| val chooser = Intent.createChooser(intent, "Choose an App") | |
| startActivity(chooser) | |
| } | |
| intent.resolveActivity(packageManager) != null -> startActivity(intent) | |
| else -> Toast.makeText(this, "No App to launch with", Toast.LENGTH_LONG).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
| <?xml version="1.0" encoding="utf-8"?> | |
| <network-security-config> | |
| <!-- Don't allow clear text traffic for all domains unless is not in the domain-config --> | |
| <base-config cleartextTrafficPermitted="false" /> | |
| <!-- Special configuration to some domains --> | |
| <domain-config cleartextTrafficPermitted="true"> | |
| <domain includeSubdomains="true">localhost</domain> | |
| <trust-anchors> | |
| <!-- Trust a debug certificate in addition to the system certificates --> |
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 numpy as np | |
| def haversine_distance(row): | |
| lat_p, lon_p = row['Pickup Lat'], row['Pickup Long'] | |
| lat_d, lon_d = row['Destination Lat'], row['Destination Long'] | |
| radius = 6371 # km | |
| dlat = np.radians(lat_d - lat_p) | |
| dlon = np.radians(lon_d - lon_p) | |
| a = np.sin(dlat/2) * np.sin(dlat/2) + np.cos(np.radians(lat_p)) * np.cos(np.radians(lat_d)) * np.sin(dlon/2) * np.sin(dlon/2) |
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
| from sklearn.cluster import KMeans ,AgglomerativeClustering | |
| # creates 5 clusters using hierarchical clustering. | |
| agc = AgglomerativeClustering(n_clusters =5, affinity='euclidean', linkage='ward') | |
| train['pickup cluster'] = agc.fit_predict(train[['Pickup Lat','Pickup Long']]) | |
| # creates 5 clusters using k-means clustering algorithm. | |
| kmeans = KMeans(5) | |
| clusters = kmeans.fit_predict(train[['Pickup Lat','Pickup Long']]) | |
| train['pickup cluster'] = kmeans.predict(train[['Pickup Lat','Pickup Long']]) |
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 folium | |
| # create the map. | |
| map_pickup = folium.Map( location=[-1.317755,36.830370]) | |
| # adding the latitude and longitude points to the map. | |
| train.apply(lambda row:folium.CircleMarker(location=[row["Pickup Lat"], row["Pickup Long"]] ).add_to(map_pickup), axis=1) | |
| # display the map: just ask for the object representation in juypter notebook. | |
| map_pickup |
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
| from geopy.geocoders import Nominatim | |
| # create the locator | |
| geolocator = Nominatim(user_agent="myGeocoder") | |
| # getting the location address | |
| location = geolocator.reverse("52.509669, 13.376294") | |
| print(location) | |
| # >>> result : Backwerk, Potsdamer Platz, Tiergarten, Mitte, Berlin, 10785, Deutschland |
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 numpy as np | |
| train['pickup x'] = np.cos(train['Pickup Lat']) * np.cos(train['Pickup Long']) | |
| train['pickup y'] = np.cos(train['Pickup Lat']) * np.sin(train['Pickup Long']) | |
| train['pickup z'] = np.sin(train['Pickup Lat']) |
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 and create the VarianceThreshold object. | |
| from sklearn.feature_selection import VarianceThreshold | |
| vs_constant = VarianceThreshold(threshold=0) | |
| # select the numerical columns only. | |
| numerical_x_train = x_train[x_train.select_dtypes([np.number]).columns] | |
| # fit the object to our data. | |
| vs_constant.fit(numerical_x_train) |
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
| # transpose the feature matrice | |
| train_features_T = x_train.T | |
| # print the number of duplicated features | |
| print(train_features_T.duplicated().sum()) | |
| # select the duplicated features columns names | |
| duplicated_columns = train_features_T[train_features_T.duplicated()].index.values | |
| # drop those columns |
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
| # make a threshold for quasi constant. | |
| threshold = 0.98 | |
| # create empty list | |
| quasi_constant_feature = [] | |
| # loop over all the columns | |
| for feature in x_train.columns: | |
| # calculate the ratio. |