Showing posts with label build. Show all posts
Showing posts with label build. Show all posts

Monday, March 26, 2012

Product Basket Problem

Hi,
I have to build a Poduct basket mining mode

Hi,

I have to build a Product basket mining mode such that when a customer selects

a product the model should be able to recommend him/her some more products.

I have a customer, product transaction table.

I have come across many typical examples where the output is

as follows

CustomerRecommended Products

Cust1a, b, c…….

Cust2e, b,

f……….

But I want the output of the model to be as follows

ProductRecommendedProducts

AB, C, D…….

BE, D, A…….

CD, A, F……

How should my mining model structure and the prediction

query look like?

Your model would look the same - all you would really want to do is to change how you query the model.

Essentially, the question you are asking is "if a customer bought product 'A', what other products might they buy". This is the same as "If customer 1 has product A in their basket, what products should I recommend." Therefore you need a query like this:

SELECT 'A' as [Product], Predict(Products,5) as [Recommended Products]
FROM MyRecommendationModel
NATURAL PREDICTION JOIN
(SELECT (SELECT 'A' as Product) AS Products) AS t

If you wanted to do this for all individual products, you would have to create a shaped input query from your product table. For example

SELECT t.Product, Predict(Products, 5) FROM [My Recommendation Model]
PREDICTION JOIN
SHAPE
{ OPENQUERY(MyDataSource],'SELECT Product FROM Products ORDER BY Product') }
APPEND
( {OPENQUERY([MyDataSource],'SELECT Product FROM Products ORDER BY Product'}
RELATE [Product] TO [Product])
AS [Products]
AS [t]
ON [My Recommendation Model].Products.Product=t.Products.Product

Friday, March 23, 2012

Produce data -> Store in table?

Hi!

I'm quite new to T-SQL and is about to build a small reporting db using SQL.
Most of the data I can move with normal INSERT INTO ... SELECT, but there are some tables that I want to
produce using T-SQL. For example I want to build a Date table like..

Date
Year
Quarter
Month
WeekDay
...

With some precalculated values for each date.

I've searched the forum but have not found any information on how to produce table contents in a good manner. I would appreciate if someone would have the time to point me in the right direction. I do not want to do this by code in my application.

My first thought is to use some kind of Insert Cursor in a While loop...

Pseudo:

declare cursor ex for 'Insert table ... '

while
begin

(produce data)
insert data

end

close cursor

While browsing the net I've got the feeling that you use cursor less in SQL Server than in other db-engines...

Have a nice day!

You could use WHILE loop without cursor:

Code Snippet

create table dates

(

Year int,

Quarter int,

Month int,

WeekDay int,

SomeData decimal

)

go

declare @.start_date datetime

declare @.end_date datetime

set @.start_date = '2007-01-01'

set @.end_date = getdate()

while @.start_date<@.end_date

begin

set @.start_date = dateadd(day, 1, @.start_date)

insert into dates values(

datepart(year,@.start_date),

datepart(quarter,@.start_date),

datepart(month,@.start_date),

datepart(weekday,@.start_date),

rand() --Just for demo

)

end

go

select * from Dates

|||

Best have a calendar table (you can add all the nessasary columns here), fill the table with required date range, join with your table & use the required calculations,

Code Snippet

create table calendar

(

year int,

quarter int,

month int,

weekday int,

date datetime primary key

)

Go

create proc fill_calendar(@.start_date datetime,@.end_date datetime)

as

begin

set nocount on;

while @.start_date <= @.end_date

begin

insert into calendar

select

datepart(year,@.start_date),

datepart(quarter,@.start_date),

datepart(month,@.start_date),

datepart(weekday,@.start_date),

@.start_date

where

not exists(select 1 from calendar where date=@.start_date);

set @.start_date = dateadd(day, 1, @.start_date)

end

end

go

--Fill your calendar when required

exec fill_calendar '1/1/2000','12/31/2007'

select * from calendar

go

select

year --other columns

,sum(yourtable.calculation)

from

calendar

inner join yourtable on yourtable.datefield = calendar.date

group by

year --other columns

Monday, March 12, 2012

Processing after new data

I'm trying to build a cube in the "real world" for the first time. I had my fact table populated with one day's worth of data, set up my time dimension using named calculations based on a datetime within the DS View of the fact table (a la the Larsen book), then built and deployed and everything worked great.

However, when I added the next day's worth of data into the fact table and tried to get it to process incrementally (and then fully), the processing fails and it looks like it's complaining about those named calculations that worked so well on day one. Any thoughts on what I might be missing here? Thanks

Errors in the OLAP storage engine: The attribute key cannot be found: Table: dbo_fact_ALI, Column: YearOfBid, Value: 2006; Table: dbo_fact_ALI, Column: QuarterOfBid, Value: 2006Q2; Table: dbo_fact_ALI, Column: MonthOfBid, Value: 200607; Table: dbo_fact_ALI, Column: DayOfBid, Value: 20060702; Table: dbo_fact_ALI, Column: HourOfBid, Value: 00:00. Errors in the OLAP storage engine: The record was skipped because the attribute key was not found. Attribute: Time Key of Dimension: Dim Time from Database: ALI DM 2, Cube: ALI DM 2, Measure Group: Fact ALI, Partition: Fact ALI, Record: 577. Errors in the OLAP storage engine: The process operation ended because the number of errors encountered during processing reached the defined limit of allowable errors for the operation. Errors in the OLAP storage engine: An error occurred while processing the 'Fact ALI' partition of the 'Fact ALI' measure group for the 'ALI DM 2' cube from the ALI DM 2 database.

You must process each dimension before the cube if you have updated your source system since the last day.

HTH

Thomas Ivarsson

Processing a CUBE

Hi,

I have one doubt in my mind. If I build a cube on dt.st Oct. next time when in 1st Dec. I want to see the same cube with effect upto 1st Dec. do I need to process the cube in order to get effect till 1st Dec.?

Nilkanth Desai

If you have to add new data then yes have to prossess the cube, you can do a incremental process|||

Thanks for your reply.

Nilkanth

Wednesday, March 7, 2012

Process Hangs

the OK status is:

I build 12 fact table point to 12 partitions, and a father-son dimention. the dimention get to the fact table by the key column(son). I processFull,processUpdate the dimention, it run well. I processFull the cube or the partition, it run well too.

The Hangs status is:

I use the Process Dimention component in the SSIS. I chose the dimention, and use an ole db Source component point to the dimention table,and in it I use a query to chose the new row:"select from AgentDim where newdata=1". In the IDE, run the package, it's OK. Then I save the package to file system, and run it by Sql Server Job Agent.

Then it hangs, the job to run the package never stop. I stop the AS service and restart it. And I get into the Management Studio, and try to Process, then found it hangs.

I tried ProcessFull, ProcessAdd, ProcessUpdate, I tried deal with cube,dimention and any object, all hangs. It seem to AS is already dead.

God save me.

thanks.

Further Info: the query to chose the new row will return 0 rows.

Found Something, I think I found a bug.

The Hangs status happened when you do this:

The query to chose the new row returns 0 rows, that will make SSIS try to put a NULL set into AS,but AS don't know how to deal with such a NULL set, so it just keeps stop there.

This is really make me angry. We will get new rows everytime if we processAdd? Ofcause not.