Beispiel #1
0
 def test_fit(self):
     domain = DateTimeDomain()
     X = numpy.array([
         "1960-01-01T00:00:00", "1960-01-01T00:00:01",
         "1960-01-01T00:01:00", "1959-12-31T23:59:59", "1960-01-03T03:30:03"
     ])
     Xt = domain.fit_transform(X)
     self.assertEqual([
         datetime(1960, 1, 1, 0, 0, 0),
         datetime(1960, 1, 1, 0, 0, 1),
         datetime(1960, 1, 1, 0, 1, 0),
         datetime(1959, 12, 31, 23, 59, 59),
         datetime(1960, 1, 3, 3, 30, 3)
     ], Xt.tolist())
Beispiel #2
0
	def test_timedelta_seconds(self):
		X = DataFrame([["2018-12-31T23:59:59", "2019-01-01T00:00:00"], ["2019-01-01T03:30:03", "2019-01-01T00:00:00"]], columns = ["left", "right"])
		mapper = DataFrameMapper([
			(["left", "right"], [DateTimeDomain(), SecondsSinceYearTransformer(year = 2010), ExpressionTransformer("X[0] - X[1]")])
		])
		Xt = mapper.fit_transform(X)
		self.assertEqual([[-1], [12603]], Xt.tolist())
Beispiel #3
0
	def test_timedelta(self):
		X = DataFrame([["2020-01-01"], ["2020-01-01T00:01:00"], ["2020-01-01T05:23:30"]], columns = ["timestamp"])
		mapper = DataFrameMapper([
			(["timestamp"], [DateTimeDomain(), SecondsSinceMidnightTransformer()])
		])
		Xt = mapper.fit_transform(X)
		self.assertEqual([[0], [60], [19410]], Xt.tolist())
Beispiel #4
0
 def test_fit_transform(self):
     X = DataFrame([["1959-12-31", "1959-12-31T23:59:59"],
                    ["1960-01-01", "1960-01-01T01:01:10"],
                    ["2003-04-01", "2003-04-01T05:16:27"]],
                   columns=["date", "datetime"])
     domain = clone(DateDomain())
     Xt = domain.fit_transform(X)
     self.assertEqual([
         datetime(1959, 12, 31),
         datetime(1960, 1, 1),
         datetime(2003, 4, 1)
     ], Xt["date"].tolist())
     self.assertEqual([
         datetime(1959, 12, 31),
         datetime(1960, 1, 1),
         datetime(2003, 4, 1)
     ], Xt["datetime"].tolist())
     Xt = domain.fit_transform(X.values)
     self.assertEqual([
         datetime(1959, 12, 31),
         datetime(1960, 1, 1),
         datetime(2003, 4, 1)
     ], Xt[:, 0].tolist())
     domain = clone(DateTimeDomain())
     Xt = domain.fit_transform(X)
     self.assertEqual([
         datetime(1959, 12, 31, 0, 0, 0),
         datetime(1960, 1, 1, 0, 0, 0),
         datetime(2003, 4, 1, 0, 0, 0)
     ], Xt["date"].tolist())
     self.assertEqual([
         datetime(1959, 12, 31, 23, 59, 59),
         datetime(1960, 1, 1, 1, 1, 10),
         datetime(2003, 4, 1, 5, 16, 27)
     ], Xt["datetime"].tolist())
     Xt = domain.fit_transform(X.values)
     self.assertEqual([
         datetime(1959, 12, 31, 0, 0, 0),
         datetime(1960, 1, 1, 0, 0, 0),
         datetime(2003, 4, 1, 0, 0, 0)
     ], Xt[:, 0].tolist())
Beispiel #5
0
store_csv(df, "Apollo")


def build_apollo(mapper, name):
    pipeline = PMMLPipeline([("mapper", mapper),
                             ("classifier", DecisionTreeClassifier())])
    pipeline.fit(df, df["success"])
    store_pkl(pipeline, name)
    success = DataFrame(pipeline.predict(df), columns=["success"])
    success_proba = DataFrame(
        pipeline.predict_proba(df),
        columns=["probability(false)", "probability(true)"])
    success = pandas.concat((success, success_proba), axis=1)
    store_csv(success, name)


mapper = DataFrameMapper([(["launch", "return"], [
    DateTimeDomain(),
    DaysSinceYearTransformer(year=1968),
    ExpressionTransformer("X[1] - X[0]")
])])

build_apollo(mapper, "DurationInDaysApollo")

mapper = DataFrameMapper([(["launch", "return"], [
    DateTimeDomain(),
    SecondsSinceYearTransformer(year=1968),
    ExpressionTransformer("X[1] - X[0]")
])])

build_apollo(mapper, "DurationInSecondsApollo")