Esempio n. 1
0
 def test_seconds_transform(self):
     X = numpy.array([
         datetime(1960, 1, 1),
         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)
     ])
     transformer = SecondsSinceYearTransformer(year=1960)
     self.assertEqual([0, 1, 60, -1, 185403],
                      transformer.transform(X).tolist())
Esempio n. 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())
Esempio n. 3
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")