Пример #1
0
 def transform(self, X, y=None):
     nyc_center = (40.7141667, -74.0063889)
     X["nyc_lat"], X["nyc_lng"] = nyc_center[0], nyc_center[1]
     args_pickup = dict(start_lat="nyc_lat", start_lon="nyc_lng",
                        end_lat="pickup_latitude", end_lon="pickup_longitude")
     args_dropoff = dict(start_lat="nyc_lat", start_lon="nyc_lng",
                         end_lat="dropoff_latitude", end_lon="dropoff_longitude")
     X['pickup_distance_to_center'] = haversine_vectorized(X, **args_pickup)
     X['dropoff_distance_to_center'] = haversine_vectorized(X, **args_dropoff)
     return X[["pickup_distance_to_center", "dropoff_distance_to_center"]]
Пример #2
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     return pd.DataFrame(haversine_vectorized(X, 
          start_lat=self.start_lat,
          start_lon=self.start_lon,
          end_lat=self.end_lat,
          end_lon=self.end_lon))
Пример #3
0
 def transform(self, X, y=None):
     assert isinstance(X, pd.DataFrame)
     if self.distance_type == "haversine":
         X["distance"] = haversine_vectorized(X, **dist_args)
     if self.distance_type == "euclidian":
         X["distance"] = minkowski_distance()
     return X[["distance"]]
Пример #4
0
    def transform(self, X, y=None):
        """Returns a copy of the DataFrame X with only one column: 'distance'"""
        X['distance'] = haversine_vectorized(X,
                                             start_lat="pickup_latitude",
                                             start_lon="pickup_longitude",
                                             end_lat="dropoff_latitude",
                                             end_lon="dropoff_longitude")

        return X[['distance']]
Пример #5
0
 def transform(self, X, y=None):
     assert isinstance(X, pd.DataFrame)
     if self.distance_type == "haversine":
         X["distance"] = haversine_vectorized(X, **DIST_ARGS)
     if self.distance_type == "euclidian":
         X["distance"] = minkowski_distance(X, p=2, **DIST_ARGS)
     if self.distance_type == "manhattan":
         X["distance"] = minkowski_distance(X, p=1, **DIST_ARGS)
     return X[["distance"]]
Пример #6
0
 def transform(self, X, y=None):
     assert isinstance(X, pd.DataFrame)
     X_ = X.copy()
     X_["distance"] = haversine_vectorized(X_,
                                           start_lat=self.start_lat,
                                           start_lon=self.start_lon,
                                           end_lat=self.end_lat,
                                           end_lon=self.end_lon)
     return X_[['distance']]
Пример #7
0
    def transform(self, X, y=None):
        jfk_center = (40.6441666667, -73.7822222222)
        X["jfk_lat"], X["jfk_lng"] = jfk_center[0], jfk_center[1]
        args_pickup = dict(start_lat="jfk_lat",
                           start_lon="jfk_lng",
                           end_lat="pickup_latitude",
                           end_lon="pickup_longitude")
        args_dropoff = dict(start_lat="jfk_lat",
                            start_lon="jfk_lng",
                            end_lat="dropoff_latitude",
                            end_lon="dropoff_longitude")
        X['pickup_distance_to_jfk'] = haversine_vectorized(X, **args_pickup)
        X['dropoff_distance_to_jfk'] = haversine_vectorized(X, **args_dropoff)

        X['from_to_airport'] = (np.logical_or(X['pickup_distance_to_jfk']<2,\
            X['dropoff_distance_to_jfk']<2))*1

        #return X[["pickup_distance_to_center", "dropoff_distance_to_center",'from_to_airport']]
        return X[['from_to_airport']]
Пример #8
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance_to_center'"""
     nyc_center = (40.7141667, -74.0063889)
     X["nyc_latitude"], X["nyc_longitude"] = nyc_center[0], nyc_center[1]
     args = dict(start_lat="nyc_latitude",
                 start_lon="nyc_longitude",
                 end_lat="pickup_latitude",
                 end_lon="pickup_longitude")
     X['distance_to_center'] = haversine_vectorized(X, **args)
     return X[['distance_to_center']]
Пример #9
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     assert isinstance(X, pd.DataFrame)
     X_temp = X.copy()
     X_temp['distance'] = haversine_vectorized(X_temp,
                                               start_lat=self.start_lat,
                                               start_lon=self.start_lon,
                                               end_lat=self.end_lat,
                                               end_lon=self.end_lon)
     return X_temp[['distance']]
Пример #10
0
    def transform(self, X, y=None):
        """Returns a copy of the DataFrame X with only one column: 'distance'"""
        X['distance'] = haversine_vectorized(X,
                                             start_lat=self.start_lat,
                                             start_lon=self.start_lon,
                                             end_lat=self.end_lat,
                                             end_lon=self.end_lon)

        X = X.reset_index(drop=True)
        return X[['distance']]
Пример #11
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     assert isinstance(X, pd.DataFrame)
     X_temp = X.copy()
     X_temp['nyc_lat'] = 40.7141667
     X_temp['nyc_lon'] = -74.0063889
     X_temp['distance_to_center'] = haversine_vectorized(
         X_temp,
         start_lat=self.nyc_lat,
         start_lon=self.nyc_lon,
         end_lat=self.end_lat,
         end_lon=self.end_lon)
     return X_temp[['distance_to_center']]
Пример #12
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     return pd.DataFrame(haversine_vectorized (X.copy(),self.start_lat,self.start_lon,self.end_lat,self.end_lon))\
                         .rename(columns={0:"distance"})
Пример #13
0
 def transform(self, X, y=None):
     a = haversine_vectorized(X)
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     return pd.DataFrame(a)
Пример #14
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only 1 column: 'distance'"""
     df = pd.DataFrame(haversine_vectorized(X.copy()))
     df.columns = ['distance']
     return df
Пример #15
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     assert isinstance(X,pd.DataFrame)
     X_ = X.copy() 
     X_['distance'] = haversine_vectorized(X_)
     return X_[['distance']]
Пример #16
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     return pd.DataFrame(haversine_vectorized(X.copy()),columns=['distance']) \
                         .sort_index()
Пример #17
0
 def transform(self, X, y=None):
     return pd.DataFrame(haversine_vectorized(X))
Пример #18
0
def test_haversine():
    df = get_data(nrows=1)
    assert round(haversine_vectorized(df)[0], 2) == 1.03, "Distance not right"
Пример #19
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     X_ = X.copy()
     X_["distance"] = haversine_vectorized(X_)
     distance = pd.DataFrame(X_["distance"])
     return distance
Пример #20
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     X = X.copy()
     X['distance'] = haversine_vectorized(X)
     return X[['distance']]
Пример #21
0
 def transform(self, X, y=None):
     """Returns a copy of the DataFrame X with only one column: 'distance'"""
     a = pd.DataFrame()
     a['distance'] = haversine_vectorized(X)
     return a